Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I validate noscript+meta refresh tag in xHTML?

For visitors that don't support JavaScript, 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 <head> 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.

like image 351
Jorre Avatar asked Aug 31 '10 14:08

Jorre


Video Answer


1 Answers

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 JavaScript 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.

like image 107
2ndkauboy Avatar answered Sep 21 '22 03:09

2ndkauboy