无 Javascript 检测脚本 + 重定向 [英] No-Javascript Detection Script + Redirect
问题描述
我想编写一个脚本来检测用户是否禁用了 javascript,如果是,则将他们重定向到另一个页面(比如 mysite.com/enablejavascript)
I would like to write a script that detects whether the user has javascript disabled, and if yes, redirect them to another page (let's say mysite.com/enablejavascript)
但是,我不知道从哪里开始!谢谢.
However, I have no idea where to start! Thanks SO.
推荐答案
Gdoron 已经提到了 noscript.结合元刷新¹,您可以重定向禁用了 JavaScript 的用户.
Gdoron mentioned noscript already. Together with meta refresh¹ you can redirect users if they have JavaScript disabled.
JavaScript 重定向可以通过 location.replace(URL)代码>
.
A JavaScript redirect can be done with location.replace(URL)
.
<head>
<noscript>
<meta http-equiv="refresh" content="0; url=http://example.com/without-js" />
</noscript>
<script>
location.replace('http://example.com/with-js');
</script>
</head>
noscript+meta 刷新示例:http://pastehtml.com/view/bsrxxl7cw.html一个>
Example of noscript+meta refresh: http://pastehtml.com/view/bsrxxl7cw.html
1) 注意维基百科文章的缺点部分!
1) Mind the drawbacks section of the Wikipedia article!
元刷新标签有一些缺点:
Meta refresh tags have some drawbacks:
- 如果页面重定向过快(少于 2-3 秒),使用下一页的返回"按钮可能会导致某些浏览器移回重定向页面,然后会再次发生重定向.这对可用性不利,因为这可能会导致读者卡在"上一个网站上.
- 读者可能希望也可能不想被重定向到其他页面,这可能会导致用户不满或引起对安全的担忧.
这篇关于无 Javascript 检测脚本 + 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!