javascript - 检测网站浏览器上的 javascript 禁用情况

标签 javascript jquery html c

不久前,我在我的 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/

相关文章:

javascript - 异步存储返回函数而不是值

javascript - 跨域或 CDN 加载 Mustache.js/Handlebars.js 模板的最佳实践

javascript - 下拉圆形单选按钮、Bootstrap...事件按钮

javascript - jQuery 和动态库

javascript - 提交表单后如何动态添加到表中

html - 如何在 ngModel 中使用两个属性?

javascript - onMouseOver 重复改变图片的背景颜色

javascript - jQuery 如何在 each() 中向前看?

html - 在 html 中使用 django 的 if 语句有多安全?

javascript - Onclick 无法使用外部 .JS 文件