开发者

Dojo - Add an External stylesheet outside of the header

开发者 https://www.devze.com 2023-04-11 08:03 出处:网络
I would like to add an external style sheet specified inside of an Ajax call. I have found a way to do this with jQuery (see the example below), however i need to adapt the method to the dojo JavaScr

I would like to add an external style sheet specified inside of an Ajax call.

I have found a way to do this with jQuery (see the example below), however i need to adapt the method to the dojo JavaScript framework.

JQuery Example

$('head').append('<link rel="styleshe开发者_Go百科et" type="text/css" href="lightbox_stylesheet.css">');

Thanks.


Once you've included dojo.NodeList-manipulate, it's virtually identical to jQuery:

dojo.require("dojo.NodeList-manipulate");

dojo.ready(function(){
    dojo.query("head").append('<link rel="stylesheet" type="text/css" href="lightbox_stylesheet.css">');
});


Try this, using dojo.query

dojo.query("head").forEach(function(node, index, array){
// append content af final of head
node.innerHTML += '<link rel="stylesheet" type="text/css" href="lightbox_stylesheet.css">';});


I came up with

After a little messing around i've come up with the following:

function require_css(href)
{
   if (typeof href == 'undefined' || href.length == 0) return false;

   var link = dojo.create("link", 
   {
      type  : "text/css",
      rel   : "stylesheet",
      href  : href
   });

   dojo.doc.getElementsByTagName("head")[0].appendChild(link);
   console.log("loading : css : "+ href);
}

Thanks for the input guys.. I prefer thirtydot's method to mine :D..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号