How can I identify Safari?

G

Giuseppe Chielli

Hi to everyone? Can someone tell me if there is a way to identify
Safari...I found out that navigator.appName 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.
 
M

Michael Winter

Giuseppe said:
Can someone tell me if there is a way to identify Safari...

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

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

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
 
G

Giuseppe Chielli

Michael said:
Reliably? I doubt you can. Why do you want to, anyway?

Because I need to prevent the bug of not getting window.innerWidth
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
 
F

Fred Oz

Giuseppe said:
Hi to everyone? Can someone tell me if there is a way to identify
Safari...I found out that navigator.appName returns "Netscape" and I

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

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

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:

I need to distinguish Safari from other browsers...

You haven't provided any reasonable reason for needing to do so.
Thanks to everyone.

No problem. :)
 
G

Giuseppe Chielli

Fred said:
You haven't provided any reasonable reason for needing to do so.

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.innerWidth 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.
 
F

Fred Oz

Giuseppe said:
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.innerWidth 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.

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...ari+iframe+innerwidth&rnum=1#7563a3defc6e9418>

(please repair wrapping if required...)

Post again if you need more help with it.
 
R

RobB

Fred said:
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:
(please repair wrapping if required...)

Post again if you need more help with it.

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=setTimeout(\'location="@"\',1000)>wait</body>'; /* demo only */
return HTML.replace(/@/, redir_url);
}

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

[untested]
 
R

RobB

Make that...

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

Thomas 'PointedEars' Lahn

RobB said:
Make that...

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

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

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

If that.


PointedEars
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top