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

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...