简体   繁体   中英

How can I detect whether JavaScript is disabled using prototype?

How can I detect whether JavaScript is disabled using the prototype library? I don't want to use the <noscript> tag; I want to use something that prototype offers.

It would be pretty hard to use javascript to detect if javascript is disabled.

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. It will do exactly the same thing as a noscript tag.

<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. You have to use the <noscript> tag.

You can't detect that javascript is disabled using javascript. Google graceful degradation, and also progressive enhancement.

You can't use JavaScript to determine if JavaScript is enabled; 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. If JavaScript is disabled, Prototype will not run, making a JavaScript enabled check useless.

You will need to use a <noscript> tag to handle situations where JavaScript is disabled.

Just thought I'd add to the myriad of comments already that question how you are to use javascript with javascript disabled. Make sure it degrades well of course.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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