This seems to work very easily in IE:
var ss = document.createStyleSheet(“/js/test/com/mentics/comp/TableTest.css”);
alert(“ss rules: “+document.styleSheets[1].rules.length);
But since Firefox/Mozilla doesn’t have createStyleSheet, what’s the right way to do this same thing in Firefox?
After some searching, I found:
[url]http://cse-mjmcl.cse.bris.ac.uk/blog/2005/08/18/1124396539593.html
And so tried this code:
var styles = “@import url(‘/js/test/com/mentics/comp/TableTest.css’);”;
var newSS=document.createElement(‘link’);
newSS.rel=’stylesheet’;
newSS.href=’data:text/css,’+escape(styles);
document.getElementsByTagName(“head”)[0].appendChild(newSS);
alert(“ss rules: “+document.styleSheets[1].cssRules.length);
But I get an error:
Error: uncaught exception: [Exception… “A parameter or an operation is not supported by the underlying object” code: “15” nsresult: “0x8053000f (NS_ERROR_DOM_INVALID_ACCESS_ERR)” location: “
I’m using Firefox 1.5 beta 2.
Thanks!