how to load external css file if javascript is disabled.
Should work in IE 6 to 9, Firefox, Google Chrome, Safari
I tried <noscript> and supported <noscript> internally, but didn't work in IE 7
<noscript>
I would do it the other way around. Always download css that will contain the rules with the prefix body.jsEnabled . Then just add the class "jsEnabled" to the body through javascript.
body.jsEnabled
This method of "detection capabilities" is approximately equal to http://www.modernizr.com/ .
I tested this method in IE7 and it works. Put <style> tags (instead of <link> in <noscript>
<style>
<link>
<noscript> <style type="text/css"> @import url (yourexternalfile.css); body{ background-color: purple; } </style> </noscript>
EDIT:
Here is a screenshot of this work in IE7.
Try the following:
<html> <head> <script type="text/javascript"> document.write('<'+'!--'); </script> <link rel="stylesheet" type="text/css" href="non-js.css"> <!-- --> </head> <body> <script type="text/javascript"> document.write('<'+'!--'); </script> Visible when no-JS <!-- --> Always visible </body> </html>
Hack, but it is correct with HTML. If JS is enabled, then the comment start control tag is printed on the page - then the second start tag is ignored, and the end tag closes the commented content. Therefore, if JS is enabled, the link tag will be commented out and will not be loaded at all.
link
and <noscript> not allowed in <head> , and <link> + <style> allowed only in <head> , you can also use this:
<head>
<link id="noscriptStyle" rel="stylesheet" type="text/css" href="my_external_css_file.css" /> <script type="text/javascript"> document.getElementById('noscriptStyle').parentNode.removeChild(document.getElementById('noscriptStyle')); </script>
But I myself would prefer the method posted by cherouvim
CSS files have nothing to do with javascript enabled / disabled ...
<link rel="stylesheet" type="text/css" href="my_external_css_file.css" />