Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to load an external css file if javascript is disabled

how to load an external css file if javascript is disabled.

Should work in IE 6 to 9, Firefox Google chrome, Safari

I tried <noscript> And keeping <noscript> inside but it's not working in IE 7

like image 561
Jitendra Vyas Avatar asked Sep 29 '10 13:09

Jitendra Vyas


2 Answers

I'd do it the other way around. Always load the css which will contain rules prefixed with body.jsEnabled. Then simply add a class "jsEnabled" on body via javascript.

This way of "discovering capabilities" is approximately how http://www.modernizr.com/ works.

like image 132
cherouvim Avatar answered Sep 28 '22 07:09

cherouvim


I've tested this method in IE7, and it works. Putting <style> tags (instead of a <link> within the <noscript>

<noscript>
<style type="text/css">
 @import url (yourexternalfile.css);

body{
background-color: purple;
}

</style>
</noscript>

EDIT:

Here's a screenshot of this working in IE7. alt text

like image 23
Yahel Avatar answered Sep 28 '22 08:09

Yahel