简体   繁体   English

如何使用原型检测是否禁用了JavaScript?

[英]How can I detect whether JavaScript is disabled using prototype?

How can I detect whether JavaScript is disabled using the prototype library? 如何使用原型库检测是否禁用了JavaScript? I don't want to use the <noscript> tag; 我不想使用<noscript>标签; I want to use something that prototype offers. 我想使用原型提供的东西。

It would be pretty hard to use javascript to detect if javascript is disabled. 使用javascript来检测javascript是否被禁用将非常困难。

To answer your subquestion, if you want to emulate <noscript> tag behavior without using noscript, make a <div> element with the content you want to show to non-javascript users, and then hide it with javascript on DOMReady event. 要回答您的子问题,如果您想模拟<noscript>标记行为而不使用noscript,请创建一个<div>元素,其中包含要显示给非JavaScript用户的内容,然后在DOMReady事件中使用javascript将其隐藏。 It will do exactly the same thing as a noscript tag. 它将执行与noscript标签完全相同的操作。

<script type="Text/JavaScript">
document.observe("dom:loaded", function() {
  $('simulate_noscript').hide();
});
</script>

<div id="simulate_noscript">
This is some content only users with JS disabled will see.
</div>

Since Prototype is JavaScript, you cannot use it to detect whether Javascript is disabled or not. 由于原型是JavaScript,因此您不能使用它来检测是否禁用了Javascript。 You have to use the <noscript> tag. 您必须使用<noscript>标记。

You can't detect that javascript is disabled using javascript. 您无法检测到使用javascript禁用了javascript。 Google graceful degradation, and also progressive enhancement. Google正常降级,并逐步增强。

You can't use JavaScript to determine if JavaScript is enabled; 您不能使用JavaScript来确定是否启用了JavaScript。 if it's not, then the script will never run. 如果不是,那么脚本将永远不会运行。 Instead, look to inject behaviours which require script using scripts themselves. 相反,请尝试使用脚本本身注入需要脚本的行为。 This is a core principle of progressive enhancement . 这是逐步增强的核心原则。

嗯,如果禁用了Javascript,原型永远也不会运行我的朋友。

Prototype is a JavaScript framework. 原型是一个JavaScript框架。 If JavaScript is disabled, Prototype will not run, making a JavaScript enabled check useless. 如果禁用了JavaScript,则Prototype将不会运行,从而使启用JavaScript的检查无效。

You will need to use a <noscript> tag to handle situations where JavaScript is disabled. 您将需要使用<noscript>标记来处理禁用JavaScript的情况。

Just thought I'd add to the myriad of comments already that question how you are to use javascript with javascript disabled. 只是以为我已经在无数评论中添加了这个问题,即如何使用禁用了javascript的javascript。 Make sure it degrades well of course. 当然,请确保其性能良好。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM