I have two frames. The pages in both frames come from the same domain (either localhost or a live domain - both using the same protocol).
The first frame needs to access elements of the second frame (xsample) when it's fully loaded and any onload JS functions have completed. But the second frame takes a while to load.
<frameset cols="*,*" rows="*" border="0" framespacing="0">
<frame src="picker.asp" name="xpicker" frameborder="no" marginwidth="15" marginheight="15">
<frame src="doc.asp" name="xsample" frameborder="no" marginwidth="15" marginheight="15">
</frameset>
The code below works in IE and Firefox but not in Chrome or Safari, In those parent.xsample
is always false
function startWork(){
if(isSurveyLoaded()==false){
SL=setTimeout("startWork()",1000);
return;
}
else{
setTimeout("doMoreWork()",2000);
}
}
function isSurveyLoaded(){
if(!parent.xsample){
return false;
}
if(!parent.xsample.self.name){
return false;
}
if(parent.xsample.document.readyState!='complete'){
return false;
}
else{
return true;
}
}
Use parent.frames["xsample"]
to access the frame.
Implicit references to named elements on the global
object is not standardized.
On a different note, never do setTimeout("doMoreWork(), 1000)"
as this forces the VM to use eval to execute the code.
Use setTimeout(doMoreWork, 1000)
which is the proper way to do it.