admin管理员组文章数量:1242803
How to check if the user disabled javascript in his browser? For example: the stackoverflow site shows a red warning div at the top if you disable the javascript in firefox? How to achieve this?
One more thing I noticed: if you disable cookies, stackoverflow doesn't work. It won't let you login when you click the login button. Actually, that's what I assume with my website as well, the user login/session data depends on cookies, UI layout etc.. depends on javascript.
Here I don't want to discuss about the design principle (progressive enhancement etc..), could anyone tell me a good way to check if cookies, javascript are enabled or not? I think it has to be done on server side, right?
Thank you
How to check if the user disabled javascript in his browser? For example: the stackoverflow site shows a red warning div at the top if you disable the javascript in firefox? How to achieve this?
One more thing I noticed: if you disable cookies, stackoverflow doesn't work. It won't let you login when you click the login button. Actually, that's what I assume with my website as well, the user login/session data depends on cookies, UI layout etc.. depends on javascript.
Here I don't want to discuss about the design principle (progressive enhancement etc..), could anyone tell me a good way to check if cookies, javascript are enabled or not? I think it has to be done on server side, right?
Thank you
Share Improve this question edited May 3, 2012 at 11:32 THelper 15.6k6 gold badges67 silver badges105 bronze badges asked Jan 19, 2010 at 23:40 WilliamLouWilliamLou 1,9046 gold badges28 silver badges38 bronze badges3 Answers
Reset to default 18Add a <noscript>
tag to the page, and if JavaScript is disabled, the message will show to the user.
You can also detect if JavaScript is enabled based on the success of running JavaScript code
- add a hidden field and set its default value to
false
- Run some javascript code that sets the value to
true
- When you post back, check the value.
To check for cookies, set a cookie and try to read it. If it succeeds, then cookies are enabled.
<!-- gatewayPage.php -->
<noscript>
<div style="background-color:red;font-size:14pt;">
This site will be very boring unless you enable Javascript!
</div>
<!-- if you're convinced that bots won't follow your redirect, add this: -->
Proceed to <a href="myRealHomePage.php">MySite</a> anyway
</noscript>
<script>
documment.location = "myRealHomePage.php";
</script>
Use the noscript tag:
<script>
document.write("JS is enabled!");
</script>
<noscript>JS is disabled !</noscript>
source : http://www.w3schools./tags/tag_noscript.asp
本文标签: cookiesHow to check if javascript is disabledStack Overflow
版权声明:本文标题:cookies - How to check if javascript is disabled? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740085621a2223713.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论