Javascript 检测NoScript(不是标记,而是扩展名)
NoScript似乎阻止了javascript在我的站点上的加载,并阻止了登录覆盖,这对站点非常重要 有什么方法可以检测NoScript扩展并提醒用户吗 编辑添加:看起来你们很多人都不明白我的意思,或者我不清楚。我说的不是Javascript 检测NoScript(不是标记,而是扩展名),javascript,firefox,noscript,Javascript,Firefox,Noscript,NoScript似乎阻止了javascript在我的站点上的加载,并阻止了登录覆盖,这对站点非常重要 有什么方法可以检测NoScript扩展并提醒用户吗 编辑添加:看起来你们很多人都不明白我的意思,或者我不清楚。我说的不是标记,而是NoScript Firefox扩展,我如何检测用户是否安装和/或启用了它。在HTML中使用块: <noscript> This site requires Javascript. Please enable Javascript in your brow
标记,而是NoScript Firefox扩展,我如何检测用户是否安装和/或启用了它。在HTML中使用
块:
<noscript>
This site requires Javascript. Please enable Javascript in your browser for this site.
</noscript>
此站点需要Javascript。请在此网站的浏览器中启用Javascript。
由于
内容仅在禁用JavaScript时显示,因此不能使用警报(因为它是JavaScript)。如果您需要提醒注意站点需要JavaScript才能正常运行,那么您需要一些CSS
一种可能是在
中粘贴一个
标记,该标记加载一个包含规则的CSS文件,以隐藏除错误消息之外的所有内容。一个非常简单的示例(仅使用嵌入的
标记):
.noscript{display:none;}
很抱歉此站点需要JavaScript。请在浏览器中启用它。
Lorem ipsum dolor sit amet,是一位杰出的献身者。毛里斯·本德·布兰迪特·拉库斯。无节律或无节律。两人坐在阿梅特·伊尼姆和塞德·莫莱斯蒂·马萨之间。利奥·努克的普鲁恩。我只是一只猫,我是一个智者,我是一个世仇。要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严,就要有尊严。舌兰发酵液中的箭毒。两人坐在阿梅特面前,告别厄洛斯。毛里斯·拉西尼亚·奥托尔·塞德·阿库姆桑。
自由女神,牛膝,发酵分子。Donec fringilla pharetra neque和ullamcorper。海棠属植物,芸香属植物,舌苔属植物,海棠属植物。在弗林尼利亚·厄罗斯·马蒂斯的小教堂里。无便利。Mauris eu Elite id tellus ornare sollicitudin quis nec lacus。一只猫的前庭是三体的,它的前庭是三体的,它的前庭是三体的,前庭是三体的,前庭是三体的,前庭是三体的,前庭是三体的,前庭是三体的,前庭是三体的。
这是一个不可否认的事实,一个不可否认的事实。佩伦特式的精英赌注,巨大的人马座id,一个假象。Phasellus eros tellus,eleifend sit amet tellus vel,porta ultrices Elite。前庭小庭,孕妇马蒂斯的舌苔,我的白兰地,亨德雷特苏打水和毛里斯坐在阿梅特。Morbi congue Impermi,vitae vulputate neque euismod a。佩伦特斯式的圣洁,封建元素的直径,阿尔库·埃尼姆·福西布斯·里苏斯,但暂时的利奥·麦格纳坐在奥古斯的位子上。Donec justo nisi,lacinia和risus at,dapibus ultrices risus。在《猫的意见》中。在玉米粉圆饼中,添加了孕妇生命中的智囊。
我使用的方法如下
<head>
<style>
.noscript-error {
background-image: url(noscript.php)
}
</style>
<style>
@import url(chrome://noscript/skin/browser.css);
</style>
</head>
<body>
<div class="noscript-error">If noscript is NOT installed (and enabled) then Firefox will make a request for noscript.php.
</div>
</body>
在
noJS.php
中,您可以编写一个脚本,并在该脚本中设置一个会话变量,或者存储信息 据我所知,不可能专门检测NoScript扩展。我假设您希望向使用NoScript的用户和仅禁用JavaScript的用户显示自定义消息,但不幸的是,这是不可能的
处理这一问题的一个好方法是在
标记中显示某种警告消息,内容大致如下:“您必须启用JavaScript才能使用此站点。”
安装了NoScript的用户将知道这意味着什么,并将相应地禁用它。NoScript将阻止所有JavaScript。因此,只需使用JS隐藏警告消息,如果警告消息仍然存在,则会启用NoScript(或者通常禁用JS)
测试
警告您已禁用JS或正在使用NoScript,这将破坏此网站!请激活JS或停用NoScript以继续。
...
document.getElementById('noscript').style.display='none';
- 不带NoScript的用户进入页面->执行JS并隐藏消息
- 使用NoScript的用户进入您的页面->JS未执行,消息不会被隐藏
<html>
<head>
<meta http-equiv="refresh" content="3; URL=http://www.yourpage.com?javascript=false">
<script type="text/javascript">
location.href = "http://www.yourpage.com?javascript=true";
</script>
</head>
<body>
<span>Please wait while the page is loading ...</span>
<noscript>If nothing happens follow this <a href="http://www.yourpage.com?javascript=false">link</a>.</noscript>
</body>
</html>
location.href=”http://www.yourpage.com?javascript=true";
正在加载页面,请稍候。。。
如果什么都没有发生,那么就这样做。
如果用户启用了Javascript,他将立即被转发到http://www.yourpage.com?javascript=true
您知道他启用了javascript
如果禁用Javascript,用户将被转发到http://www.yourpage.com?javascript=false
3秒钟后,通过meta-http equiv=“refresh”
标记,该标记在不使用Javascript的情况下工作
作为回退,有一个链接供浏览器中禁用Javascript和其他转发方法的用户使用
现在您有了两个独立的页面,您可以允许用户登录并使用或不使用JavaCScript
注意事项:
- 这不是NoScript所特有的(当通过其他方式禁用Javascript时,它也会起同样的作用)
- 所有用户在访问您的页面时都会有延迟
- 您的URL包含javascript参数,看起来有点难看。您可以使用两个不同的页面,而不是o
<noscript> <img src="noJS.php" alt="JavaScript is disabled" /> </noscript>
<html> <head> <title>test</test> </head> <body> <div id="noscript">Warning! You have disabled JS or you're using NoScript which will break this site! Please active JS or deactivate NoScript to continue.</div> <div id="content"> ... </div> <script type="text/javascript"> document.getElementById('noscript').style.display = 'none'; </script> </body> </html>
<html> <head> <meta http-equiv="refresh" content="3; URL=http://www.yourpage.com?javascript=false"> <script type="text/javascript"> location.href = "http://www.yourpage.com?javascript=true"; </script> </head> <body> <span>Please wait while the page is loading ...</span> <noscript>If nothing happens follow this <a href="http://www.yourpage.com?javascript=false">link</a>.</noscript> </body> </html>
<div id="js-disabled-warning"> <div class="message"> <p>You're using this site with javascript disabled (set by manually or with a browser extension like NoScript)!</p> <p>Javascript is essential for using this site. Please enable it!</p> <p>Here you can get some help: <a href="http://www.enable-javascript.com" target="_blank">http://www.enable-javascript.com</a></p> </div> </div> <div class="site-content"> <p>Here comes your site content!</p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Deleniti inventore velit sint aspernatur nemo quasi in officia doloribus dolores deserunt nostrum quas. Excepturi recusandae eum libero sint necessitatibus corporis id.</p> </div>
#js-disabled-warning { position: absolute; top: 0; left: 0; right: 0; bottom: 0; margin: auto; background: rgba(0,0,0,.5); } #js-disabled-warning .message { position: absolute; top: 0; left: 0; right: 0; bottom: 0; margin: auto; display: table; width: 30%; background: #bada55; padding: 20px; border-radius: 5px; }
(function() { var alert_modal = document.getElementById('js-disabled-warning'); alert_modal.parentNode.removeChild(alert_modal); })();
<html> <head> <title>noscript detect</title> </head> <body> <div id="noJavascript"> Your browser does not have javascript enabled. This site requires javascript to operate properly. Please enable javascript. </div> <script type="text/javascript"> var noJavascript = document.getElementById("noJavascript"); noJavascript.parentNode.removeChild(noJavascript); </script> </body> </html>