Javascript bug in Safari ???

S

Shiva

This is my HTML Page containing javascript

---------------------------------------------------
<html>
<head>
<script language="JavaScript">

var isSafari = (agent.indexOf("Safari") != -1); // LINE 1

var myimg = new Object(); // LINE 2

function myfn() { alert("Hello"); }

function writemyfn() {

//myimg = new Object(); // LINE 3

document.write('<a href="javascript:myfn()"');
if (document.images) {
myimg.hi = new Image();
myimg.hi.src = "some.gif";
document.write('onmouseover="document.images.open.src=myimg.hi.src">');
}
document.write('<img name="open" src="some.gif"></a>');
}

</script>
</head>
<body>
<script language=JavaScript>
writemyfn();
</script>
</body>
</html>

---------------------------------------------------

With the above HTML, the image doesn't show on Safari
(running Safari 1.3 (v312) on Mac Mini)

If I remove LINE 1, the image starts displaying correctly.
However, I cannot do that in my actual HTML page.

Other workarounds, are if I change
LINE 2 to "var myimg = null;"
& uncomment LINE3 - then again the image starts
displaying.


Is this a known Bug in Safari? Where can it be reported?
 
D

Daniel Kirsch

Shiva said:
var isSafari = (agent.indexOf("Safari") != -1); // LINE 1

Is your variable "agent" defined? Or do you mean the userAgent property
of the navigator object?

var isSafari = (navigator.userAgent.indexOf("Safari") != -1);

Remember, the userAgent string must no show the UA's real name. So
checking for existing properties instead of the userAgent might be better.

Daniel
 
S

Shiva

Daniel said:
Is your variable "agent" defined? Or do you mean the userAgent
property of the navigator object?

var isSafari = (navigator.userAgent.indexOf("Safari") != -1);

Changing the agent to navigator.userAgent does fix the problem.
Remember, the userAgent string must no show the UA's real name.

I don't understand.
So
checking for existing properties instead of the userAgent might be
better.

Can you elaborate?
 
D

Daniel Kirsch

Shiva said:
I don't understand.

Using Firefox or Opera the user is able to change the string returned by
navigator.userAgent.
This was mainly introduced because a lot of developers checked the
browser and it's vendor this way and eg. showed a simple "wrong browser,
you must have InternetExplorer", although the page does actually work
with the latest version of other browsers too.

Can you elaborate?

That depends on what you want to do and why you are using this browser
check.

eg. if you want to use the all collection from InternetExplorer to
access elements, you may not check for InternetExplorer, but check for
the all collection as other browsers may also implent it or a new
version of InternetExplorer will not support it anymore (which I doubt)
and the userAgent string must not be correct:

function getElm(id) {
if (document.all)
return document.all[id];
else if (document.getElementById)
return document.getElementById(id);
return null;
}

Daniel
 

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
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top