6
4
What's the correct syntax to link to a CSS file in the same directory as a Greasemonkey JavaScript? I've tried the following but it doesn't work:
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'example.css';
cssNode.media = 'screen';
cssNode.title = 'dynamicLoadedSheet';
document.getElementsByTagName("head")[0].appendChild(cssNode);
If I can get this to work, it would be a lot easier than encasing CSS changes in JavaScript.
1any reason for not using GM_addStyle() ? – ukanth – 2010-01-12T10:59:04.187
No, just personal preference :) I just find making many changes can be a bit tedious. I also find it easier to spot mistakes in a CSS file (syntax highlighting helps). – Umber Ferrule – 2010-01-12T12:04:49.610