No-Javascript检测脚本+重定向 [英] No-Javascript Detection Script + Redirect

查看:107
本文介绍了No-Javascript检测脚本+重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个脚本来检测用户是否禁用了javascript,如果是,则将其重定向到另一个页面(假设为mysite.com/enablejavascript)



<但是,我不知道从哪里开始!非常感谢。

解决方案

Gdoron已经提到了noscript。与元刷新¹一起,如果用户禁用了JavaScript,您可以重定向用户。



可以使用 location.replace(URL)

 < head> 
< noscript>
< meta http-equiv =refreshcontent =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)注意缺点部分!


元刷新标签有一些缺点:




  • 如果页面重定向太快(少于2-3秒) ,使用下一页上的后退按钮可能会导致某些浏览器移回重定向页面,然后重定向将再次发生。这对可用性不利,因为这可能会导致读者在最后一个网站上卡住。

  • 读者可能希望或不希望被重定向到不同的页面,这可能导致用户不满或引起对安全性的担忧。



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 mentioned noscript already. Together with meta refresh¹ you can redirect users if they have JavaScript disabled.

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>

Example of noscript+meta refresh: http://pastehtml.com/view/bsrxxl7cw.html

1) Mind the drawbacks section of the Wikipedia article!

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.

这篇关于No-Javascript检测脚本+重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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