简体   繁体   English

我可以创建一个按钮来启用javascript吗

[英]Can I create a button to enable javascript

Is there any way to create a button to enable javascript if a user doesn't have it enabled? 如果用户未启用某个按钮,是否可以创建任何按钮来启用javascript?

If not, is there another way to enable javascript in the user's browser automatically when they visit our website? 如果没有,还有没有其他方法可以在用户访问我们的网站时自动在用户的浏览器中启用javascript?

Failing that, can I access the user's browser settings with permission and then enable javascript? 如果失败,我是否可以在获得许可的情况下访问用户的浏览器设置,然后启用javascript?

No. 没有。

If a user has disabled JavaScript then there is no way for a website to do anything (other then provide instructions (eg in <noscript> )) to "help" them turn it on. 如果用户禁用了JavaScript,那么网站将无法做任何事情(然后提供说明(例如,在<noscript> ))来“帮助”他们打开网站。

Given that people disabling JS are, increasingly, using third party tools (such as NoScript) to do so, providing instructions isn't likely to be helpful anyway. 鉴于禁用JS的人们越来越多地使用第三方工具(例如NoScript)来执行此操作,因此提供说明无论如何都无济于事。 If a user has disabled JavaScript, then it is safe to assume that they understand the consequences of doing so and are capable of finding the On switch for themselves. 如果用户禁用了JavaScript,则可以安全地假定他们了解这样做的后果,并且能够自己找到“打开”开关。

JavaScript can fail for other reasons though (such as a network problem while the JS file was downloading), so always be progressive and unobtrusive . JavaScript 可以失败但其他原因(如网络问题,而JS文件下载),所以始终是渐进的不显眼

Have you considered using a <noscript> tag? 您是否考虑过使用<noscript>标记?

<noscript>
     <div class="bigRedWarningBoxInMiddleOfScreen">
        Enable javascript pretty please
      </div>
</noscript>

不,如果网页可以控制浏览器的安全性设置,那我们就该死了!

The only thing you can do is to check if JavaScript is disabled. 您唯一可以做的就是检查JavaScript是否已禁用。 If it is you can show a page that guides the user with enabling it. 如果是这样,则可以显示一个指导用户启用它的页面。

No but next best thing you could do is: 不,但是您可以做的下一件最好的事情是:

<noscript>
    <div class="alert alert-error">Please enable JavaScript to use this site properly, here's <a href="http://www.enable-javascript.com/" target="_blank">how</a></div>
</noscript>

I believe that site detects which browser the user is using and gives directions accordingly. 我相信该网站会检测到用户正在使用哪个浏览器,并给出相应的指示。

Some people don't like noscript for some reason so you could do: 有些人由于某种原因不喜欢noscript,因此您可以这样做:

<div id="noscript">
    <div class="alert alert-error">Please enable JavaScript to use this site properly, here's <a href="http://www.enable-javascript.com/" target="_blank">how</a></div>
</div>

and

document.getElementById('noscript').style.display = 'none';

But this might cause a flicker if your page size is large. 但是,如果您的页面很大,可能会导致闪烁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一旦所有字段都输入正确,如何使用 javascript 启用“创建帐户”按钮? - How can I use javascript to enable a “create account” button once all fields have correct input? 如何使用JavaScript创建透明按钮? - How can I create a transparent button with JavaScript? 我无法在javascript中再次启用该按钮 - I cant enable the button again in javascript 如何使用JavaScript禁用/启用基于单选按钮的选择选项 - How can i disable/enable select option based on radio button with JavaScript Javascript:当使用同一类检查其他 15 个单选按钮时,如何启用单选按钮? - Javascript: How can I enable a radio button when 15 other radio buttons are checked with the same class? 如何从 Javascript 调用 ext.net 按钮并设置为启用它? - How I can call ext.net button from Javascript and set to enable it? 如何启用表单中的提交按钮? - how can i enable the submit button in the form? 如何使用Greasemonkey启用禁用按钮? - How can I enable a disabled button with Greasemonkey? 如何使用Javascript使用Sprite Sheet创建动画按钮? - How can I create an Animated Button with a Sprite Sheet using Javascript? Javascript Calculator:如何根据条件创建操作员按钮? - Javascript Calculator: How can I create an operator button based on a condition?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM