Safari and Window.onload timing

R

Rainmanjam

I have an issue with using window.onload with Safari. I am trying to
use Microsoft Live maps and it works with Firefox and IE. When I look
at the forums out there, there is a firing issue with window.onload
and safari. Here is the script I am running:

<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?
v=6" type="text/javascript"></script>
<script src="javascript/VEMapFunctions.js" type="text/javascript"></
script>
<script type="text/javascript">window.onload = GetMap;</script> //
getmap is in the js script
<title>
XXXXXXXX
</title></head>

<body>
<div id='myMap' style="position: relative; width: 750px; height:
500px;">
</body>


Should I be using something else?
 
R

Rainmanjam

Rainmanjam said the following on 12/24/2007 1:43 AM:


And what issue is that?


And what issue is that?
There is a timing issue with Safari. Safari does not wait until the
page is loaded before running a window.onload. Therefor none of the
information in the VEMapFunctions.js run.
Maybe something that will get you to explain what the issue is.

http://ajaxian.com/archives/safari-3-onload-firing-and-bad-timing is
the issue. I don't know javascript well to insert this into the JS I
have currently.
 
R

RobG

There is a timing issue with Safari. Safari does not wait until the
page is loaded before running a window.onload. Therefor none of the
information in the VEMapFunctions.js run.

The page you referenced says quite specifically that Safari waits for
all resources to be loaded before firing onload, so you can't blame
that.

If you want to test it, use setTimeout to delay the call to your
function, then see how short the lag needs to be to get reliable
operation, e.g.:

window.onload = function() {
setTimeout('GetMap();', 0);
}


A link to a page would be better.

[...]
 
R

Rainmanjam

There is a timing issue with Safari. Safari does not wait until the
page is loaded before running a window.onload. Therefor none of the
information in the VEMapFunctions.js run.

The page you referenced says quite specifically that Safari waits for
all resources to be loaded before firing onload, so you can't blame
that.

If you want to test it, use setTimeout to delay the call to your
function, then see how short the lag needs to be to get reliable
operation, e.g.:

window.onload = function() {
setTimeout('GetMap();', 0);

}

A link to a page would be better.

[...]

http://njection.com/speedtrap

It works in IE and FF.. Not in Opera.
 
M

My Pet Programmer

Rainmanjam said:
I have an issue with using window.onload with Safari.
And what issue is that?
I am trying to use Microsoft Live maps and it works with Firefox and
IE. When I look at the forums out there, there is a firing issue with
window.onload and safari.
And what issue is that?
There is a timing issue with Safari. Safari does not wait until the
page is loaded before running a window.onload. Therefor none of the
information in the VEMapFunctions.js run.
The page you referenced says quite specifically that Safari waits for
all resources to be loaded before firing onload, so you can't blame
that.

If you want to test it, use setTimeout to delay the call to your
function, then see how short the lag needs to be to get reliable
operation, e.g.:

window.onload = function() {
setTimeout('GetMap();', 0);

}
Here is the script I am running:
A link to a page would be better.

[...]

http://njection.com/speedtrap

It works in IE and FF.. Not in Opera.

What about this article?

http://peter.michaux.ca/article/553

I'm using that code, and it's working in my safari on Windows Vista,
maybe it'll work for what you're doing?

~A!
 
M

My Pet Programmer

My Pet Programmer said:
I'm using that code, and it's working in my safari on Windows Vista,
maybe it'll work for what you're doing?

~A!

Sorry, I haven't tested on Opera, but it's worth a shot. I misread.
 
R

Rainmanjam

Rainmanjam said the following on 12/24/2007 3:06 AM:




How is anybody supposed to be able to help you if you can't even make up
your mind what browser it does or doesn't work in? First it was Safari,
now it is Opera, will it be Ice Weasel next?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Sorry.. it is is Safari. MSN live maps do not work with Opera. Sorry
for the confusion
 
M

My Pet Programmer

Randy Webb said:
How is anybody supposed to be able to help you if you can't even make up
your mind what browser it does or doesn't work in? First it was Safari,
now it is Opera, will it be Ice Weasel next?
I needed that grin tonight, Randy. Thanks. ;)

~A!
 
M

My Pet Programmer

Rainmanjam said:
You guys are brutal..:)

Oh, no offense on you, dude. You should have been around earlier, when I
was getting my ass kicked. Don't take it personally, everyone here is
trying to help.

Like I said, no offense to you, his comment just made me grin. You have
to admit, it would have been funny if it wasn't you, right? :)

~A!
 
R

Rainmanjam

Rainmanjam said:



Oh, no offense on you, dude. You should have been around earlier, when I
was getting my ass kicked. Don't take it personally, everyone here is
trying to help.

Like I said, no offense to you, his comment just made me grin. You have
to admit, it would have been funny if it wasn't you, right? :)

~A!

Nahh.. its cool. Never personal. Can you guy help with the above issue?
 
M

My Pet Programmer

Rainmanjam said:
Nahh.. its cool. Never personal. Can you guy help with the above issue?

Did you see the link I posted? The code at the end of that article does
some very cool things with polling the DOM to see if the element you
want is cool to use. Check it out.

~A!
 
R

Rainmanjam

Rainmanjam said:





Did you see the link I posted? The code at the end of that article does
some very cool things with polling the DOM to see if the element you
want is cool to use. Check it out.

~A!

Sorry about that. I see the code. How would I tie that code into what
I am using?
 
M

My Pet Programmer

Rainmanjam said:
Sorry about that. I see the code. How would I tie that code into what
I am using?

I would take the listing for onContentAvailable.js, stick it in a file,
and source it in through a script tag.

<script src="onContentAvailable.js" type="text/javascript"></script>

And then in the head, assign the event to your function:


onContentAvailable=function('elementID', functionName);

Where elementID is the element you're looking for, and functionName is
the function you want to run, defined presumably somewhere else in your
code. Or you could to it as an anonymous inline function, your call on
that one.

And once the elm you're looking for is ready the event fires, and your
function runs. No guarantees it's what you want, but it's definitely
worth the effort to try.

~A!
 
R

Rainmanjam

Rainmanjam said:





I would take the listing for onContentAvailable.js, stick it in a file,
and source it in through a script tag.

<script src="onContentAvailable.js" type="text/javascript"></script>

And then in the head, assign the event to your function:

onContentAvailable=function('elementID', functionName);

Where elementID is the element you're looking for, and functionName is
the function you want to run, defined presumably somewhere else in your
code. Or you could to it as an anonymous inline function, your call on
that one.

And once the elm you're looking for is ready the event fires, and your
function runs. No guarantees it's what you want, but it's definitely
worth the effort to try.

~A!

What elementID do you suggest I ise?
 
M

My Pet Programmer

Rainmanjam said:
[snip]
What elementID do you suggest I ise?
Well, probably one you're going to try to manipulate with the function.

Take a break and get some coffee, this stuff is always better when you
stop staring at it for a minute.

~A!
 
R

RobG

The page you referenced says quite specifically that Safari waits for
all resources to be loaded before firing onload, so you can't blame
that.
If you want to test it, use setTimeout to delay the call to your
function, then see how short the lag needs to be to get reliable
operation, e.g.:
window.onload = function() {
  setTimeout('GetMap();', 0);
A link to a page would be better.

http://njection.com/speedtrap

It works in IE and FF.. Not in Opera.

When I try to load that page in Safari I get;

TypeError: Value null (result of expression window.attachEvent) is not
object.
http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6

The script file is obfuscated and minified, I'm not going any further
- the script file uses extensive browser sniffing. Suffice to say
Safari does not support IE's proprietary attachEvent, it supports the
W3C's addEventListener and DOM 0 window.onload.

The page is not valid XHTML (93 errors, some quite serious):

<URL:
http://validator.w3.org/check?uri=h...(detect+automatically)&doctype=Inline&group=0
 
R

RobG

Rainmanjam said:





Did you see the link I posted? The code at the end of that article does
some very cool things with polling the DOM to see if the element you
want is cool to use. Check it out.

The intention of that code is to call functions *before* the onload
event occurs that would otherwise be called *after* onload. In other
words, it is attempting to pre-empt window.onload.

There does not seem any point in polling to see if some element is
available in the body if the issue in question is whether a script
element in the head has loaded.

As far as I can tell, the issue has nothing to do with the claim that
Safari fires the load event early - nothing in this thread supports
that assertion.
 
M

My Pet Programmer

RobG said:
As far as I can tell, the issue has nothing to do with the claim that
Safari fires the load event early - nothing in this thread supports
that assertion.

You're most likely correct, I wasn't sure what he wanted, made the
suggestion, and just followed up. If it's the wrong thing for what he
needs, then I apologize to the OP for leading him down the wrong path,
definitely.

~A!
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top