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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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