How can I identify Safari?

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

    #1

    How can I identify Safari?

    Hi to everyone? Can someone tell me if there is a way to identify
    Safari...I found out that navigator.appNa me returns "Netscape" and I
    didn't found any option to change the browser's definition...
    I can use document.all for IE, and so on but what can I do with Safari?
    I need to distinguish Safari from other browsers...

    Thanks to everyone.
  • Michael Winter

    #2
    Re: How can I identify Safari?

    Giuseppe Chielli wrote:
    [color=blue]
    > Can someone tell me if there is a way to identify Safari...[/color]

    Reliably? I doubt you can. Why do you want to, anyway?
    [color=blue]
    > [...] I can use document.all for IE[/color]

    No, you can't. Opera and IceBrowser both support the all collection.
    Other user agents might, too.
    [color=blue]
    > I need to distinguish Safari from other browsers...[/color]

    I very much doubt that. Your time would probably be better spent
    learning how to implement feature detection. See section 4.26 of the
    group FAQ, and its linked articles.

    Mike

    Comment

    • Fred Oz

      #3
      Re: How can I identify Safari?

      Giuseppe Chielli wrote:[color=blue]
      > Hi to everyone? Can someone tell me if there is a way to identify
      > Safari...I found out that navigator.appNa me returns "Netscape" and I[/color]

      Safari can masquerade as many browsers, you can't reliably identify
      it (nor most browsers) using appName.
      [color=blue]
      > didn't found any option to change the browser's definition...[/color]

      A Safari user can change the user agent that Safari masquerades as,
      but you, as an HTML/script author, can't.
      [color=blue]
      > I can use document.all for IE, and so on but what can I do with Safari?[/color]

      Changing the browser that Safari pretends to be will not change its
      support (or lack thereof) for Microsoft's proprietary (but sometimes
      copied) document.all. There are DOM methods that provide the same
      functionality that are implemented across a much wider range of
      browsers, including Safari.

      IE 6 implements pretty much all of them, IE 5 does most and 4 quite a
      few. There are simple ways to allow for both MS proprietary and DOM
      interfaces - read the FAQ:

      <URL:http://www.jibbering.c om/faq/>
      [color=blue]
      > I need to distinguish Safari from other browsers...[/color]

      You haven't provided any reasonable reason for needing to do so.
      [color=blue]
      >
      > Thanks to everyone.[/color]

      No problem. :-)

      --
      Fred

      Comment

      • Giuseppe Chielli

        #4
        Re: How can I identify Safari?

        Michael Winter wrote:
        [color=blue]
        > Reliably? I doubt you can. Why do you want to, anyway?[/color]

        Because I need to prevent the bug of not getting window.innerWid th
        property when a document is loaded in a frame... I see now that I can
        test if this property is null or undefined... I just had to pay more
        attention... ;)
        Thanks anyway.

        Giuseppe

        Comment

        • Giuseppe Chielli

          #5
          Re: How can I identify Safari?

          Fred Oz wrote:
          [color=blue]
          > You haven't provided any reasonable reason for needing to do so.[/color]

          I told about that in a post and now I'll explain it better: I have a GIS
          web application and the map image is in a frame; when the window is
          resize, the Javascript code works for arranging the size of the image
          and it does it using window.innerWid th property.
          Because of a bug, in Safari this property doesn't return the correct
          value if a document is loaded in a frame (it works properly only without
          frames) so I'd like to prevent from resizing window when Safari is used.
          I hope to have been clear...

          Thanks.

          Comment

          • Fred Oz

            #6
            Re: How can I identify Safari?

            Giuseppe Chielli wrote:[color=blue]
            > Fred Oz wrote:
            >[color=green]
            >> You haven't provided any reasonable reason for needing to do so.[/color]
            >
            >
            > I told about that in a post and now I'll explain it better: I have a GIS
            > web application and the map image is in a frame; when the window is
            > resize, the Javascript code works for arranging the size of the image
            > and it does it using window.innerWid th property.
            > Because of a bug, in Safari this property doesn't return the correct
            > value if a document is loaded in a frame (it works properly only without
            > frames) so I'd like to prevent from resizing window when Safari is used.
            > I hope to have been clear...
            >
            > Thanks.[/color]

            A solution was posted by RobB on 11 April that may help, search
            this group for "Window size via Javascript for Safari (Mac)" or
            follow this:

            <URL:http://groups-beta.google.com/group/comp.lang.javas cript/browse_frm/thread/49b992a0042f308 5/7563a3defc6e941 8?q=safari+ifra me+innerwidth&r num=1#7563a3def c6e9418>

            (please repair wrapping if required...)

            Post again if you need more help with it.

            --
            Fred

            Comment

            • RobB

              #7
              Re: How can I identify Safari?

              Fred Oz wrote:[color=blue]
              > Giuseppe Chielli wrote:[color=green]
              > > Fred Oz wrote:
              > >[color=darkred]
              > >> You haven't provided any reasonable reason for needing to do so.[/color]
              > >
              > >
              > > I told about that in a post and now I'll explain it better: I have[/color][/color]
              a GIS[color=blue][color=green]
              > > web application and the map image is in a frame; when the window is[/color][/color]
              [color=blue][color=green]
              > > resize, the Javascript code works for arranging the size of the[/color][/color]
              image[color=blue][color=green]
              > > and it does it using window.innerWid th property.
              > > Because of a bug, in Safari this property doesn't return the[/color][/color]
              correct[color=blue][color=green]
              > > value if a document is loaded in a frame (it works properly only[/color][/color]
              without[color=blue][color=green]
              > > frames) so I'd like to prevent from resizing window when Safari is[/color][/color]
              used.[color=blue][color=green]
              > > I hope to have been clear...
              > >
              > > Thanks.[/color]
              >
              > A solution was posted by RobB on 11 April that may help, search
              > this group for "Window size via Javascript for Safari (Mac)" or
              > follow this:
              >
              >[/color]
              <URL:http://groups-beta.google.com/group/comp.lang.javas cript/browse_frm/thread/49b992a0042f308 5/7563a3defc6e941 8?q=safari+ifra me+innerwidth&r num=1#7563a3def c6e9418>[color=blue]
              >
              > (please repair wrapping if required...)
              >
              > Post again if you need more help with it.
              >
              > --
              > Fred[/color]

              Just fyi, you shouldn't need to fetch the 'pre-document' from the
              server; a locally assembled one should do:

              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
              "http://www.w3.org/TR/html4/str­ict.dtd">
              <html>
              <head>
              <style type="text/css">

              iframe {
              display: block;
              width: 500px;
              height: 400px;
              margin: 100px auto;
              overflow: auto;
              }

              </style>
              <script type="text/javascript">

              function if_dummy(redir_ url)
              {
              //var HTML = '<body onload=location ="@"></body>'; <-- use this
              var HTML = '<body
              onload=setTimeo ut(\'location=" @"\',1000)>wait </body>'; /* demo only */
              return HTML.replace(/@/, redir_url);
              }

              </script>
              </head>
              <body>
              <iframe
              src="javascript :parent.if_dumm y('http://www.google.com' )"></iframe>
              </body>
              </html>

              [untested]

              Comment

              • RobB

                #8
                Re: How can I identify Safari?

                Make that...

                function if_dummy(redir_ url)
                {
                var HTML = '<body onload=location .replace("@")></body>';
                return HTML.replace(/@/, redir_url);
                }

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: How can I identify Safari?

                  RobB wrote:[color=blue]
                  > Make that...
                  >
                  > function if_dummy(redir_ url)
                  > {
                  > var HTML = '<body onload=location .replace("@")></body>';[/color]
                  ^ ^ ^^ ^^[color=blue]
                  > return HTML.replace(/@/, redir_url);
                  > }[/color]

                  Don't. It is not supposed to work and it is inefficient.
                  Make it

                  function if_dummy(redir_ url)
                  {
                  return '<body onload="locatio n.replace(\''
                  + redir_url + '\')"><\/body>';
                  }

                  If that.


                  PointedEars

                  Comment

                  Working...