我该如何使用noscript标签?

时间:2015-02-10 15:18:33

标签: javascript jquery html alert noscript

当用户使用Internet Explorer登录并禁用用户的javascript设置时,我想向用户显示警告。我试过使用<noscript>标签。我已经更改了我的javascript设置(启用为禁用)以进行测试但是当我尝试它时,没有显示任何内容。我该怎么做?以下是我的代码;

<script>
  document.write("Hello World!")
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>

<p>A browser without support for JavaScript will show the text inside the noscript element.</p>

1 个答案:

答案 0 :(得分:3)

这是一个很好的。这是因为你的例子很少。浏览器自动将<script><noscript>标签包装在<head>中,这意味着当JS执行并写入&#34; Hello world&#34;时,<noscript>标签隐藏起来,因为它在<head>

如果您手动将它们放在<body>中,它可以正常工作:

&#13;
&#13;
<html><head></head>
<body>
<script>
  document.write("Hello World!")
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>

<p>A browser without support for JavaScript will show the text inside the noscript element.</p>
</body>
</html>
&#13;
&#13;
&#13;