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
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.
$(function(){$('body').addClass('jsEnabled');});<link rel="stylesheet" type="text/css" href="non-js.css"> only if javascript is disabled and want to keep this css after all other css files.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.

Try this:
<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 comment start control tag is printed into page - then second start tag is ignored and ending tag closes commented content.
So if JS is enabled link tag will be commented out and not downloaded at all.
while <noscript> is not allowed in <head>, and <link> + <style> are only allowed in <head> , you also could use this:
<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 by myself I would prefer the method posted by cherouvim
CSS-Files have nothing to do with enabled/disabled javascript...
<link rel="stylesheet" type="text/css" href="my_external_css_file.css" />