Web Analytics Made Easy -
StatCounter Use different .js files based on browser type? - CodingForum

Announcement

Collapse
No announcement yet.

Use different .js files based on browser type?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    <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>

    Comment


    • #3
      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; Jul 10, 2002, 10:41 AM.

      Comment


      • #4
        I copied and pasted the code from Tamienne into
        the <head> of a page and I receive javascript
        error messages.

        Thanks William.

        Comment


        • #5
          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>

          Comment

          Working...
          X