JavaScript Detection Hack

My site uses Javascript to submit login credentials so that I'm not sending passwords in plain text. But if someone has JavaScript turned off they can't log in.

I want to display a warning if JavaScript is disabled, but I need to use some kind of client-side code to figure out when to display it. The following script will display a JavaScript warning but simply hide it if JavaScript is available.



<!-- JS detect hack by Clint Bellanger, donated to Public Domain. -->
<span id="js_warn">You must have JavaScript enabled to log in.</span>
<script type="text/javascript">
  document.getElementById("js_warn").style.display = "none";
</script>
<!-- end JS detect hack -->

Browsers which don't use CSS (like Lynx) will always display the message.

Feel free to use this hack on your site. I've dedicated it to the Public Domain.