Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    HTML-like Comment Tags in JavaScript???

    I came across some embedded JavaScript code and I noticed some weird “HTML comment-like tags” within embedded JavaScript that are getting rendered in FireFox but not IE. Specifically the closing tag "//-->"

    And the JavaScript code between these tags is functional (not commented out)!

    Code:
    <SCRIPT type=text/javascript>
    <!--
    
    ....
    
    //-->
    </SCRIPT>
    What are these?

    Example usage:

    Code:
    <SCRIPT type=text/javascript>
    <!--
    var zz, zv, d, fTSR;
    d = new Date();
    fTSR=0;
    zv = d.getTime();
    zz = "&zz="+zv;
    
    var gBF=false;
    function GoTo(u){window.top.location = u + zz;}
    function Go(u){window.top.location = u;} 
    
    ....
    
    //-->
    </SCRIPT>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts
    Deprecated tags to hide scripts from browsers that cannot handle them.
    Remove them and all should be well

    Comments in JS are either
    // one line comment
    /*
    Multi-line
    comments
    */

  • Users who have thanked jmrker for this post:

    jeff00seattle (12-11-2010)

  • #3
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jmrker View Post
    Deprecated tags to hide scripts from browsers that cannot handle them.
    How long have they been "deprecated"?

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Arrow

    Quote Originally Posted by jeff00seattle View Post
    How long have they been "deprecated"?
    Don't remember ... don't care.

    See: http://www.w3schools.com/js/js_howto.asp
    section about "How to handle simple browsers".
    Both FF and MSIE should ignore them, but if they are giving you problems, remove them because they are not needed in NEW browsers.

    If you are trying to execute a XHTML instead of a HTML document
    see http://www.w3schools.com/tags/tag_script.asp for a discussion of the differences.

    Among other statements, in http://javascript.crockford.com/script.html it states
    Do not use the <!-- //--> hack with scripts. It was intended to prevent scripts from showing up as text on the first generation browsers Netscape 1 and Mosaic. It has not been necessary for many years. <!-- //--> is supposed to signal an HTML comment. Comments should be ignored, not compiled and executed. Also, HTML comments are not to include --, so a script that decrements has an HTML error.
    language="javascript"

    This attribute has been deprecated. It was used to select other programming languages and specific versions of JavaScript. You don't need it. Don't use it.
    type="text/javascript"

    This attribute is optional. Since Netscape 2, the default programming language in all browsers has been JavaScript. In XHTML, this attribute is required and unnecessary. In HTML, it is better to leave it out. The browser knows what to do.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by jeff00seattle View Post
    How long have they been "deprecated"?

    The <!-- and //--> comment (hiding) tags have not been necessary since IE3 (i.e. since September 1997). If you see these in some published script it is a warning that you are looking at ancient and perhaps unreliable code.

    Quote Originally Posted by jmrker View Post
    In XHTML, this attribute is required and unnecessary.
    Ah, that makes it very clear.
    Last edited by Philip M; 12-12-2010 at 07:52 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •