Detecting when a page has loaded in a sub frame via javascript?

F

foldface

Hi
Given a web page using frames, is there anyway the left frame can request a
page in the right frame and, most importantly, detect when it has fully
loaded?
Ideally this requires no changes to the original web page being loaded on
the right.
Something like document.frame2.fullyLoaded? You get the idea

Thanks
F
 
M

Martin Honnen

Given a web page using frames, is there anyway the left frame can request a
page in the right frame and, most importantly, detect when it has fully
loaded?
Ideally this requires no changes to the original web page being loaded on
the right.

With IE5.5/6 on Win you could from the first frame call

parent.document.getElementsByTagName('frame')[1].attachEvent('onload',
function (evt) {
// just an example, handle the load event here
alert(evt ? evt.type : event.type);

}
);

and then set
parent.frames[1].location = 'whatever.html';


With Mozilla and Netscape 7 you can from the first frame call

parent.document.getElementsByTagName('frame')[1].addEventListener('load',
function (evt) {
alert(evt ? evt.type : event.type);
},
true
);

and then set
parent.frames[1].location.href = 'whatever.html'

With other browsers you will have to use <body onload> in the document
loaded in the frame
 
F

foldface

thats fantastic thank you!

one other thing though...

will this tell me when the page has fully finished loading? i.e. all
images loaded and all possibly all scripts on the page run?

anyway way of finding out if the page didn't load correctly? guessing
something
like <pseduo code> if(body.text == "couldn't find page requested")
</pseudo code> or better

Thanks for you help

F
 
M

Michael Winter

[snip - use of unload event]
will this tell me when the page has fully finished loading? i.e. all
images loaded and all possibly all scripts on the page run?

Maybe, maybe not. There's no real way of telling. Different browsers use
different criteria when determining whether a page has loaded. Some
include images - some may even include Flash objects and Java applets.
anyway way of finding out if the page didn't load correctly?

[snip]

The only assured way of determining if a page loaded or not is by checking
the HTTP Response Status header, as servers may return any document when a
resource can't be loaded (so checking the contents of the page is a
possibility). Unfortunately, JavaScript cannot read the Response codes (it
can't read HTTP headers in general).

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top