开发者

How can I load a stylesheet dynamically in XULRunner?

开发者 https://www.devze.com 2023-02-07 11:58 出处:网络
When running in a web browser, I can do this to dynamically inject a stylesheet: var link = document.createElement(\'link\'),

When running in a web browser, I can do this to dynamically inject a stylesheet:

var link = document.createElement('link'),
    head = document.getElementsByTagName('HEAD')[0];

link.rel  = 'stylesheet';
link.type = 'text/css';
link.href = '/path/to/stylesheet.css';
head.appendChild(link);

Is there a way to do the same in XULRunner? I've seen you can use something called Components.interfaces.mozIJSSubScriptLoader to load JavaScript, but does the same capability开发者_如何学Python exist for CSS?


You can try using the style sheet service. Something like:

var sss = Cc["@mozilla.org/content/style-sheet-service;1"]
          .getService(Ci.nsIStyleSheetService);
var ios = Cc["@mozilla.org/network/io-service;1"] .getService(Ci.nsIIOService);
var uri = ios.newURI("chrome://pluginname/skin/notes.css", null, null);

if(!sss.sheetRegistered(uri, sss.USER_SHEET)) {
    sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
}

More examples.

0

精彩评论

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

关注公众号