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 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    352
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Hide from old browsers

    Hi;
    If i have an external JS file do i need to hide it from old browsers and if so where do i put the <!-- and //-->

    Any help will be appreciated,
    Thanks,
    MW2005

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no, don't need to hide it. non-JS browsers will just ignore the tags and anything between them as long as you include the appropriate comments, eg for HTML 4:

    PHP Code:
    <script type="text/javascript">
    <!-- 
    //


    // -->
    </script> 
    *keep it simple (TM)

  • #3
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    What is in there that older browsers shouldn't see?
    How old are the 'old browsers' you're referring to?
    Are they sufficiently popular for you to consider them?

    Fwiw…
    Code:
    <script type="text/javascript">
    <!--
    
    
    //-->
    </script>

  • #4
    Regular Coder
    Join Date
    Jul 2005
    Posts
    352
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for that,
    Do i need to do that for external JS files like:

    <script type = "text/javascript" src = "whatever.js">
    <!--

    //-->
    </script>

  • #5
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    If you were set on using comments, then simply enclose all the js code within the external js file within sgml comments.

    e.g.

    site.js
    Code:
    <!--
    
    function one() {
    	…
    }
    
    function two() {
    	…
    }
    
    function three() {
    	…
    }
    
    -->

  • #6
    Regular Coder
    Join Date
    Jul 2005
    Posts
    352
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for all of your help

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Quote Originally Posted by Bill Posters
    If you were set on using comments, then simply enclose all the js code within the external js file within sgml comments.

    e.g.

    site.js
    Code:
    <!--
    
    function one() {
    	…
    }
    
    function two() {
    	…
    }
    
    function three() {
    	…
    }
    
    -->
    That won't work. You don't need to put HTML comments inside a .js file.
    Javascript parser is different from HTML parser.

    When you include the .js file in an HTML file, you don't need to put HTML comment as there's nothing inside the script tag to hide.


    <script type="text/javascript" src="file.js"></script>

  • #8
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    I got a bum steer, guv'nor.
    I never use SGML comments around embedded js, so it's not something I have experience of, but I was already quite certain that they weren't necessary.
    I did a quick Google around for verification and the one page I could find that mentioned sgml comments and external js files mentioned it was permissable.

    That'll learn me not to trust my own knowledge.

  • #9
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Bill Posters
    I did a quick Google around for verification and the one page I could find that mentioned sgml comments and external js files mentioned it was permissable.
    yeah, because everything on the Net is correct, right enough.
    *keep it simple (TM)

  • #10
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by jbot
    yeah, because everything on the Net is correct, right enough.
    The site I alighted upon seemed as credible as this forum which, sorry to break it to you, is also on the net.

    But thanks for reminding me not to believe everything you say.

  • #11
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Bill Posters
    But thanks for reminding me not to believe everything you say.
    glad to be of service, bill.

    oh look, a flying pig ...
    *keep it simple (TM)


  •  

    Posting Permissions

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