Browse DevX
Sign up for e-mail newsletters from DevX

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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

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

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="XBbXEb5toZgH13EwHARgXAAAABE"/> <meta name="WT.qs_shmv" content="hv20180802-hale.sf.quinstreet.net"/> <meta name="inject_params" content="WT.qs_dlk=XBbXEb5toZgH13EwHARgXAAAABE&"/> <script>!function(){if(!window.BOOMR||!window.BOOMR.version){var e,t,n,o=document.createElement("iframe");o.src="javascript:false",o.title="",o.role="presentation",(o.frameElement||o).style.cssText="width:0;height:0;border:0;display:none;",(n=document.getElementsByTagName("script")[0]).parentNode.insertBefore(o,n);try{t=o.contentWindow.document}catch(n){e=document.domain,o.src="javascript:var d=document.open();d.domain='"+e+"';void(0);",t=o.contentWindow.document}t.open()._l=function(){var t=this.createElement("script");e&&(this.domain=e),t.id="boomr-if-as",t.src="/imageserver/common/sg/1.0/sg.min.js",BOOMR_lstart=(new Date).getTime(),this.body.appendChild(t)},t.write('<body onload="document._l();">'),t.close()}}();</script> <script> document.cookie = 'inject_params=WT.qs_dlk=XBbXEb5toZgH13EwHARgXAAAABE&; path=/; domain=devx.com;'; document.cookie = 'WMUUID=XBbXEb5toZgH13EwHARgXAAAABE; path=/; domain=devx.com;'; </script><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=XBbXEb5toZgH13EwHARgXAAAABE&"/></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.



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