Results 1 to 4 of 4

Thread: Change script depending on browser

  1. #1
    Join Date
    Apr 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Change script depending on browser

    Ok, I'm gettin a bit annoyed with all the hassle I'm going through the get a good navagation bar that is cross browser. I was wondering if there is someway to change a navagation bar depending on the broswer the viewer is using. I don't want the whole page to change as this would use up a lot of hosting space, i just want the script that is loaded to be different. I'd like something like one script for IE, and another for any other browser.
    This would just make the viewing of the site a lot more pleasent, but no worries if this isn't possible.
    Thanks,
    Mark

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This is very easy.
    Code:
    if(document.all) {
      // IE code
    } else {
      // other code
    }
    However, don't use browser detection too often. It's an ugly hack, and as such only suitable for compensating for other bugs -- and even then not when there is an alternative.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks. How do I write it so I can give the sources of the two scripts. And i put
    Code:
    <script language="JavaScript" type="text/javascript">
    before it?

    Also, is it possible to have two scripts to load for the none-IE one.

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    This is very easy.
    Code:
    if(document.all) {
      // IE code
    } else {
      // other code
    }
    That doesn't work at all. See a relevant Usenet post by Richard Cornford.

    Browser detection doesn't work. How many times does that need to be said?

    Mike

Bookmarks

Posting Permissions

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