如何验证xHTML中的noscript + meta刷新标签? [英] How do I validate noscript+meta refresh tag in xHTML?

查看:121
本文介绍了如何验证xHTML中的noscript + meta刷新标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于不支持JavaScript的访问者,我将其重定向到某个页面-"js.html".

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>

当然,这不能在XHTML中验证,因为必须将noscript放在<body>中. 但是,当我将该代码放在文档正文中时,又遇到了另一个错误,因为元标记只能在<head>部分中使用,所以这里有点陷入无限循环.

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.

推荐答案

您可以执行以下操作:

将meta插入您的头部,但需要2秒钟的刷新时间.紧挨着该位置的是一个SCRIPT标记,该标记删除了元刷新.因此,任何JS用户都不会被重定向:

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>

浏览器可能已经提到"了元刷新.因此,您可以使用JavaScript在其周围编写一个打开和关闭HTML注释(包括一个打开脚本标签以关闭第二个document.write的脚本标签):

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>

我可以成功测试这个.

只是有关如何处理非js用户的提示.我有一个名为"js"的css类,可将其添加到仅对javascript用户可见的任何元素中.通过javascript,我添加了一个css文件,其中包含类"js"的规则,该规则显示了具有"js"类的每个元素.所有链接(功能)均经过设计,无需使用javascript即可使用,也可以在按住CTRL键的同时单击链接的新选项卡中使用.

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.

这篇关于如何验证xHTML中的noscript + meta刷新标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆