'onload' event only once?

A

Andy Haupt

Hello ,

does the 'onload' event fire only once per window?

I was trying to load a sequence of URLs into a window by accessing the
new URL in the onload handler of the current one but my code executes
only the first onload. The script simply stops after the second url is
loaded. Why?

code is as follows:

var url = new Array(
'http://www.yahoo.com',
'http://www.google.com',
'http://www.msnbc.com'
);

var attr="scrollbars=no,toolbar=no,directories=no,resizable=no,status=no,
alwaysRaised=no,width=660,height=600";

var count = 0;
// This is the first URL to be loaded
var win = window.open( url[count], 'myWindow', attr);

// this is needed to overcome the security restrictions in Netscape
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
win.enableExternalCapture();
win.captureEvents(Event.LOAD);

// this is the onload handler: it displays an alert and loads
// the new url.
// It works the first time ie. after yahoo has loaded it shows
// the alert and loads google but nothing else happens.
win.onload = function(evt) {
alert(evt.target.name + " loaded");
count++;
win.location = url[count];
return false;
}


any pointers are appreciated.

rgds
Andy
 
M

Michael Winter

does the 'onload' event fire only once per window?
Yes.

I was trying to load a sequence of URLs into a window by accessing the
new URL in the onload handler of the current one but my code executes
only the first onload. The script simply stops after the second url is
loaded. Why?

When you load a new document into the window, it clears all of the
previously added event handlers. Modify the script to repeatedly set the
onload intrinsic event.

[snip]

Mike
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top