Linking to Different .js files Depending on Browser?

Discussion in 'HTML & Website Design' started by frontierid, Mar 30, 2006.

  1. #1
    I link to my website's menu with the following:

    <script type="text/javascript" language="javascript" src="Scripts/menu.js"></script>

    The problem that I have is that the menu is offset a bit to the left when viewed in IE, due to the Menu offset y coordinate. If I change it so that it looks good with IE, then the menu is offset in Firefox to the Right.

    So, I'm wondering if I can create a separate .js file that has the correct offset y coordinate for IE and then reference that file if the browser is IE or Opera .

    Thanks in advance for any feed back. The site is www.frontierid.com if it helps.

    I'm a bit new to this so I hopes this makes sense.
     
    frontierid, Mar 30, 2006 IP
  2. the_pm

    the_pm Peon

    Messages:
    332
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #2
    For IE, this is easy. Use a Conditional Comment to call the IE-specific .js file only for IE (this works for calling any document, including a different style sheet). You can even choose which version of IE you want to recognize the different .js file.

    Wow, I've never used that link until today, and this is the third time today I've used it, twice on IWDN and now once here. Craziness :)
     
    the_pm, Mar 30, 2006 IP
  3. brian394

    brian394 Well-Known Member

    Messages:
    226
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Instead of using two separate .js files, why not just use one with a conditional statement at the approriate line. Something like this...

    
    if (is_ie == true) {
     y = 4;
    } else {
     y = 5;
    }
    
    Code (markup):
    If it's just one variable we're talking about here, seems kinda redudant to create two seperate files. :D
     
    brian394, Apr 10, 2006 IP
  4. phd

    phd Active Member

    Messages:
    496
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #4
    phd, Apr 10, 2006 IP