不久前,我在我的 google chrome 浏览器上禁用了 javascript,并思考网站所有者将如何检测用户是否在该网站上禁用了 javascript,我在 google 上搜索并在 stackoverflow 上找到了这个问题的答案。这是链接:click to show question .
之后,我将页面的所有内容包装在 body 标记的 pagecontainer
类中,如下所示:
<body class="pagecontainer">
<noscript>
<style type="text/css">
.pagecontainer {display:none;}
</style>
<div class="noscriptmsg">
You don't have javascript enabled. Good luck with that.
</div>
</noscript>
//all page content is here
</body>
之后,我禁用了该页面的 javascript,并尝试运行该页面,但我无法获取包含在 noscriptmsg
类中的消息。因此,如果用户禁用此页面的 javascript,请帮助我们提供 noscriptmsg
类中给出的消息。
最佳答案
您的 CSS 位于 <noscript>
block 构成整个<body>
被隐藏,你的<noscript>
标签是 <body>
的一部分.
你可以将其更改为如下所示:
<body>
<noscript>
<style type="text/css">
.pagecontainer {display:none;}
</style>
<div class="noscriptmsg">
You don't have javascript enabled. Good luck with that.
</div>
</noscript>
<section class=pagecontainer>
//all page content is here
</section>
</body>
另一种方法是您可以输入 <meta>
标签在你的 <noscript>
阻止将浏览器重定向到“请启用 JavaScript”页面。这样您的普通页面就不必担心它:
<!DOCTYPE html>
<html>
<head>
<noscript>
<meta http-equiv="refresh" content="0; url=http://your.domain/noscript.html">
</noscript>
关于javascript - 检测网站浏览器上的 javascript 禁用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27781447/