
Tuesday, October 18, 2005
How to detect JavaScript in a browswer - Version 1 - Poorman's special.
This is a simple hack to detect whether JavaScript is enabled in a
browser. This trick should work for ASP.NET or Ruby on Rails or
any other framework. The trick is to use the noscript tag.
Here is a snippet of code:
<noscript>
<INPUT TYPE='hidden' NAME='jsdisabled' VALUE='true'>
<span class='warning'>JavaScript must be enabled to use this site!</span>
</noscript>
Make sure you place this code inside the form that is to be posted.
The noscript tag is only active when script is either not supported or
disabled. This chunk of code gives a warning to the user and also
sets a hidden form value. When the form is posted you can then
check to see if the jsdisabled parameter is included with the
post. If it is you know that JavaScript is enabled.
Notice I call this a poor man's method as it needs more testing.
If you can see any problems with this please add a comment so I can
change it