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 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Use different .js files based on browser type?

    How can I use different .js files based on the browser type? The below code does not work, please help.

    Thanks William.

    <script language="JavaScript1.2">
    if (document.layers) { // NetScape 4.x
    src="netscape4x_menu.js"
    }
    else { // IE or NetScape 6/Mozilla
    src="non_netscape4x_menu.js"
    }
    </script>

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Delaware, USA
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <script language="JavaScript1.2">
    if (document.layers) { // NetScape 4.x

    document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='netscape4x_menu.js' TYPE='text/javascript'><\/SCRIPT>");

    } else { // IE or NetScape 6/Mozilla
    document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='non_netscape4x_menu.js' TYPE='text/javascript'><\/SCRIPT>");

    }
    </script>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't beleive you can do that. Why don't you combine both scripts into one exteranal file?

    I stand corrected. I tested it and you can, but I still wonder why you don't combine the two scripts.
    Last edited by requestcode; 07-10-2002 at 03:41 PM.

  • #4
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I copied and pasted the code from Tamienne into
    the <head> of a page and I receive javascript
    error messages.

    Thanks William.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Make sure you don't have line breaks in there:

    Code:
    <script language="JavaScript1.2"> 
    if (document.layers) { // NetScape 4.x 
    
    document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='netscape4x_menu.js' TYPE='text/javascript'><\/SCRIPT>"); 
    
    } else { // IE or NetScape 6/Mozilla 
    document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='non_netscape4x_menu.js' TYPE='text/javascript'><\/SCRIPT>"); 
    
    } 
    </script>


  •  

    Posting Permissions

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