[Greasemonkey] Replacement for addGlobalStyle()

John gm at plsek.id.au
Tue Jul 5 15:09:40 EDT 2005


Thom Wetzel wrote:

>
>    function addGlobalStyle(string){
>        if(/microsoft/i.test(navigator.appName) && 
> !/opera/i.test(navigator.userAgent)){
>            document.createStyleSheet().cssText=string;
>        }
>        else {
>            var ele=document.createElement('link');
>            ele.rel='stylesheet';
>            ele.type='text/css';
>            ele.href='data:text/css;charset=utf-8,'+escape(string);
>            document.getElementsByTagName('head')[0].appendChild(ele);
>        }
>    }
>
There is a difference, though. Styles created this way can NOT be 
subsequently modified dynamically (at least the Mozilla ones, not sure 
about IE ones) - found that out the hard way. I think it may have to do 
with the data: "protocol"

It's great for "static" styles though.

John


More information about the Greasemonkey mailing list