Need to detect Safari Browsers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nitronic

    #1

    Need to detect Safari Browsers


    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=nav igator.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;
    }
    }



  • unruly

    #2
    Re: Need to detect Safari Browsers

    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.

    Comment

    • Randy Webb

      #3
      Re: Need to detect Safari Browsers

      Nitronic wrote:
      [color=blue]
      >
      > 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.[/color]

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



      <--garbage code snipped-->

      --
      Randy
      comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

      Comment

      • Nitronic

        #4
        Re: Need to detect Safari Browsers


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

        Hello Nitronic,
        [color=blue]
        > 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=nav igator.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;
        > }
        > }[/color]


        Comment

        • RobG

          #5
          Re: Need to detect Safari Browsers

          Nitronic <na@na.ca> wrote in message news:<367566324 77321312135296@ news.cogeco.ca> ...[color=blue]
          > Thanks for the help. Guys keep sending posts if u have any other ideas :)
          >[/color]

          I can't understand your issue.

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

          navigator.userA gent 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.

          Comment

          Working...