Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Math processing
Expertise: Beginner
Mar 19, 1997

The 'greater-than' vs. 'comment' dilemna

Question:
The 'greater-than' vs. 'comment' dilemna

Answer:
There is a trick in writing JavaScripts which all developers should learn as soon as possible. When putting a script in your HTML, you should comment out the code (using ''). The comments will keep the code from actually being written on the web page, yet won't stop the parser from loading the script. Here's a peek at what this looks like:

1. <HMTL> 2. <HEAD> <meta name="WT.qs_dlk" content="WjQpsgrIZ7gAAGMxFL4AAAAi"/> <meta name="WT.qs_shmv" content="hv20150423-pierce.sf.quinstreet.net"/> <meta name="inject_params" content="WT.qs_dlk=WjQpsgrIZ7gAAGMxFL4AAAAi&"/> <meta http-equiv="Set-Cookie" content="inject_params=WT.qs_dlk=WjQpsgrIZ7gAAGMxFL4AAAAi&; path=/; domain=devx.com;"/> <meta http-equiv="Set-Cookie" content="WMUUID=WjQpsgrIZ7gAAGMxFL4AAAAi; path=/; domain=devx.com;"/> <TITLE>A comment test</title> 3. <SCRIPT LANGUAGE=&quot;JavaScript&quot;> 4. <!-- This will hide the script from being displayed 5. . . . 6. // --> 7. </script> 8. <script> window.webtrendsAsyncInit=function(){ var dcs=new Webtrends.dcs().init({ dcsid:"dcsetaek200000gcgxfcx07g4_2p3u", domain:"www.qsstats.com", timezone:-8, i18n:true, onsitedoms:"devx.com", fpcdom:".devx.com", plugins:{ //hm:{src:"//s.webtrends.com/js/webtrends.hm.js"} } }).track(); }; (function(){ var s=document.createElement("script"); s.async=true; s.src="/imageserver/common/v10/webtrends.min.js"; var s2=document.getElementsByTagName("script")[0]; s2.parentNode.insertBefore(s,s2); }()); </script> <noscript><img alt="dcsimg" id="dcsimg" width="1" height="1" src="//www.qsstats.com/dcsetaek200000gcgxfcx07g4_2p3u/njs.gif?dcsuri=/index.php/tips/Tip/23183&amp;WT.js=No&amp;WT.tv=10.4.1&amp;dcssip=www.devx.com&amp;WT.qs_dlk=WjQpsgrIZ7gAAGMxFL4AAAAi&"/></noscript> </head> 9. <BODY>. . . </body></html>

Obviously, the line numbers above are only used for reference and not part of the HTML.

  • In line 4 you'll see that we begin a comment by using standard HTML notation: ''. This will signal that the browser should end the logical comment block that was started on line 4. This type of HTML tag is specific to Netscape, because standard HTML dictates the use of '>' to end a comment block.
The fact that Netscape uses a proprietary tag to mark the end of a comment should not suprise anybody. They have an entire set of tags which they are trying to get the rest of the internet community to adopt as standards, but which will only work on their browser. So how does this affect us as JavaScript programmers?

When a non-Netscape browser is parsing the code, it will see the standard '' tag. This means you must be careful to not use greater than sign because you won't even realize the problem exists until somebody else sees the page with a different browser!

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date