Validating JavaScript

hello readers… sorry that i have not been blogging recently. I have been caught on a few project works and are occupied most of the time.. anyways lets continue 🙂

this hack is just a simple hack, dosent require any heavy coding, just good old plain HTML. If we had to validate that the browser is javascipt enabled, we have to run some code to test it out… there are many codes available on the net to do this. But im gonna show u a simple approach that many developers fails to relaise that exist 🙂

The <noscript>, noscript element is used to define an alternate content (text) if a script is NOT executed. This tag is used for browsers that recognizes the <script> tag, but does not support the script in it. If a browser supports scripting, it will not display the text in the noscript element.

Example:

<html><body>
<noscript>
<strong>This example requires a JavaScript-enabled browser!<br/><br/></strong>
</noscript>

<script>
// this is a sample javascript to test if the <noscript> tag works
alert(“test! Hey it works”);
</script>
</body></html>

In the above example the text between the <noscript> tag is displayed only when the browser’s javascipt is disabled.
nosc1

And when u have a Javascipt enabled, the text between the <noscript> tag will not be displayed and the javascript code will be executed.
nosc2

hmmmm simple isnt it, no much of hardwork to do eh’ 🙂 no u can do this simple validation easily without much os a hassle.. hope this will help alot of people…

well anyhoo, ciao till next time…

Advertisements

About this entry