Friday, May 6, 2011

Google chrome link stylesheet tag at runtime

I'm adding a CSS link tag at runtime, it works in all the browsers except for chrome, which simply refuses to use the CSS, Its a PHP script file in which a header('Content-Type: text/css;); has been added as follows

var css;
css = '<link rel="stylesheet" type="text/css" href="http:/domain.com/cm.css?c=someval"/>';
$(css).appendTo("body");

As u can see, I'm using jQuery to append the link. It works on all browsers, IE6+, Firefox, Safari(windows) but not Chrome. Any help!?

From stackoverflow
  • Try adding the tag to the head:

    $('head').append(css);
    
    ruturaj : hey!! that worked like a charm, thanks a lot
    David Thomas : Then you should accept the answer, no? =)

0 comments:

Post a Comment