views:

16

answers:

2

For visitors that don't support JS I'm redirecting them to a certain page "js.html"

For this I have the following in all my files:

<noscript>
<meta http-equiv="Refresh" content="0;URL=js.html" />
</noscript>

Of course, this doesn't validate in xHTML as noscript must be placed in <body>. But when I place that code in the body of my document, I get another error, because meta tags can only be used in the section so I'm kind of stuck in an infinite loop here.

Is there a way to make this validate? It works fine in all browsers so it's not a big deal, I just would like to validate my app

+1  A: 

Here is what you could do:

Insert the meta into your head but with a refresh of let's say 2 seconds. And very next to that place a SCRIPT tag that removes that meta refresh. So any JS user will not be redirected:

<meta id="refresh" http-equiv="Refresh" content="10;URL=js.html" />
<script type="text/javascript">
    $('refresh').remove();
</script>

The browser might hav already "mentioned" the meta refresh. So you could just use JavasScript to write an opening and closing HTML comment (inlcude an opening script tag to close the script tag of the second document.write) around it:

<script type="text/javascript">
    document.write("<!-- ");
</script>
<meta http-equiv="Refresh" content="2;URL=js.html" />
<script type="text/javascript">
    document.write(' --><script type="text/javascript">');
</script>

I could successfully tested this one.

Just a hint on how I handle non-js users. I have a css class called "js" which I add to any element that should only be visible for javascript users. Through javascript I add a css file containing a rule for the class "js" that shows every element with the "js" class. All links (functions) are alo designed, that they can be used without javascript or in a new tab clicking a link while holding down CTRL.

Kau-Boy
A: 

As you've discovered, this problem cannot be resolved in HTML4. In HTML5 currently, however, noscript is valid in head, so you could use HTML5 for validation purposes. (The HTML5 validator is much better than the HTML4 one anyway).

One caveat though: HTML5 has an outstanding issue (ISSUE-117) which calls for deprecation of noscript, so it's possible that by the time HTML5 reaches last call, noscript will no longer be valid in HTML5.

Alohci