Popular Posts

Wednesday, March 18, 2009

Some Precautions before coding JavaScript

Before you add JavaScript to your site you should make sure that it will be compatible with all your clients browsers. That’s hard as you are not aware who may access your site from any part of world using any browser version which may be or may not be compatible with JavaScript. Here are two tips which turns out to be really helpful for me.

1. Always use “<!-- -->” tags inside the Script tags. This will turn your scripting language code into comments if and only if client browser is not compatible with JavaScript code. This will eventually hide displaying the code on the client’s browser if scripting is disabled. Here is how to use it

<script language="JAVASCRIPT" type="text/javascript"> <!-- hide code from old browsers that doesn’t support JavaScript

JavaScript code statements

--> </script>

2. Use no scripts tags for worst case scenario. The contents of this tag will visible only if the scripting is disabled. Here it is how to use it :

<NOSCRIPT> Your browser understands JavaScript. However, the feature is turned off. Please turn it on to enjoy the full capability of this page. </NOSCRIPT>

Hope this will help next time you are coding JavaScript.

No comments: