Jump to content

Browser detection to use different JS Files for positiniong


nd3_2000

Recommended Posts

Hi Guys...

 

I need to use a browser detector function so depending on which browser is being used changes whilch javascript file I use for posotiong of a drop down box....

 

Am having problems getting the code right.....

 

this is what I have

 

<script type="text/javascript">

if (navigator.userAgent.indexOf("Firefox")!=-1)

document.write("U r using Firefox")

if (navigator.userAgent.indexOf("MSIE")!=-1)

document.write("u r using IE")

</script>

 

THis is working fine and detects either browser BUT I need to add somewhere to use the different jsfile, which ioriginall looks like this

 

<SCRIPT TYPE="text/javascript" SRC="/menu/menu_data2.js"></SCRIPT>

 

So if its IE I want it to use the above file if its FF I want it to use

 

<SCRIPT TYPE="text/javascript" SRC="/menu/menu_data.js"></SCRIPT>

 

 

Can anyone help scritp this as I keep getting a blank form

 

Is your problem an IE problem? If so you are better off using conditional comments to fix this, as some users will have javascript turned off.

 

And even if it's not an IE problem and your problem is somewhere else, javascript isn't a good way to fix it. Validating your code is a good place to start. Then make sure your code works in FF or Safari, or some other non-IE browser. From there you can use conditional comments to make it work in IE if necessary.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.