How can I detect whether JavaScript is disabled using the prototype library? I don't want to use the &开发者_如何学编程lt;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.
Ummm if Javascript is disabled Prototype is never going to run my friend.
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.
精彩评论