Need to detect Safari Browsers

Discussion in 'Javascript' started by Nitronic, Mar 29, 2005.

  1. Nitronic

    Nitronic Guest

    I got this javascript code below and each time i got to a safari browser
    it thinks its netscpe any ideas. But i threw in Safari code but it doesn't
    work.

    var browserName=navigator.appName;
    // Menu offset y coordinate

    if (browserName=="Netscape")
    {
    var StartTop=97; // Menu offset x coordinate
    var StartLeft=-309;
    }
    //else
    {
    if (browserName=="Microsoft Internet Explorer")
    {
    var StartTop=105; // Menu offset x coordinate
    var StartLeft=-310;
    }
    else if (browserName=="Safari")
    {
    var StartTop=95; // Menu offset x coordinate
    var StartLeft=-130;
    }
    }
    Nitronic, Mar 29, 2005
    #1
    1. Advertising

  2. Nitronic

    unruly Guest

    IIRC, Safari's user-agent string contains "compatable". You might go
    digging for that if you want to find them. It is, of course,
    unreliable. However it works in most cases.
    unruly, Mar 29, 2005
    #2
    1. Advertising

  3. Nitronic

    Randy Webb Guest

    Nitronic wrote:

    >
    > I got this javascript code below and each time i got to a safari browser
    > it thinks its netscpe any ideas. But i threw in Safari code but it
    > doesn't work.


    That code doesn't "work" (reliably) in any browser. What browser the
    user has is irrelevant. Read this groups FAQ, specifically section 4.26

    http://jibbering.com/faq/#FAQ4_26

    <--garbage code snipped-->

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Randy Webb, Mar 29, 2005
    #3
  4. Nitronic

    Nitronic Guest

    Thanks for the help. Guys keep sending posts if u have any other ideas :)

    Hello Nitronic,

    > I got this javascript code below and each time i got to a safari
    > browser it thinks its netscpe any ideas. But i threw in Safari code
    > but it doesn't work.
    >
    > var browserName=navigator.appName;
    > // Menu offset y coordinate
    > if (browserName=="Netscape")
    > {
    > var StartTop=97; // Menu offset x coordinate
    > var StartLeft=-309;
    > }
    > //else
    > {
    > if (browserName=="Microsoft Internet Explorer")
    > {
    > var StartTop=105; // Menu offset x coordinate
    > var StartLeft=-310;
    > }
    > else if (browserName=="Safari")
    > {
    > var StartTop=95; // Menu offset x coordinate
    > var StartLeft=-130;
    > }
    > }
    Nitronic, Mar 30, 2005
    #4
  5. Nitronic

    RobG Guest

    Nitronic <> wrote in message news:<>...
    > Thanks for the help. Guys keep sending posts if u have any other ideas :)
    >


    I can't understand your issue.

    navigator.appVersion reports:
    5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/85.8.5 (KHTML,
    like Gecko) Safari/85.8.1

    navigator.userAgent reports:
    Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/85.8.5
    (KHTML, like Gecko) Safari/85.8.1

    Both strings contain 'Safari'. Of course, Safari can masquerade as
    something else, so your issue isn't always fixed.

    --
    Rob.
    RobG, Mar 31, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. El Kabong

    Browsers, browsers! Quo vadis?

    El Kabong, May 11, 2007, in forum: HTML
    Replies:
    23
    Views:
    890
    dorayme
    May 13, 2007
  2. cwdjrxyz
    Replies:
    0
    Views:
    1,927
    cwdjrxyz
    Jun 20, 2007
  3. CES
    Replies:
    2
    Views:
    99
    Martin Honnen
    Nov 30, 2004
  4. Jochem Donkers

    Problem with other browsers than Safari

    Jochem Donkers, Oct 19, 2005, in forum: Javascript
    Replies:
    7
    Views:
    109
    Randy Webb
    Oct 23, 2005
  5. Peter Michaux
    Replies:
    5
    Views:
    79
    Peter Michaux
    Nov 13, 2006
Loading...

Share This Page