无Javascript检测脚本重定向

前端之家收集整理的这篇文章主要介绍了无Javascript检测脚本重定向前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想编写一个脚本来检测用户是否禁用了 JavaScript,如果是,将其重定向到另一个页面(假设mysite.com/enablejavascript)

但是,我不知道从哪里开始!谢谢你.

解决方法

Gdoron已经提到了noscript.与 meta refresh¹一起,如果禁用JavaScript,您可以重定向用户.

可以使用location.replace(URL)完成JavaScript重定向.

<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元刷新示例:http://pastehtml.com/view/bsrxxl7cw.html

1)注意维基百科文章drawbacks部分!

Meta refresh tags have some drawbacks:

  • If a page redirects too quickly (less than 2-3 seconds),using the “Back” button on the next page may cause some browsers to move back to the redirecting page,whereupon the redirect will occur again. This is bad for usability,as this may cause a reader to be “stuck” on the last website.
  • A reader may or may not want to be redirected to a different page,which can lead to user dissatisfaction or raise concerns about security.
原文链接:https://www.f2er.com/js/154245.html

猜你在找的JavaScript相关文章