我正在尝试访问 iframe 的 iframe 的数据。要强制我的 javascript 函数等待,我使用 jqueries .load 函数。但是在 iframe 的内容完全加载之前,我的 javascript 代码仍然“有时”被执行。有时我的意思是不同计算机的行为不同。在速度较慢的计算机上,它等待速度较快的计算机的时间最多,代码几乎总是被执行。所以我怀疑 Internet Explorer 8 会提前触发 onload 事件。是否有任何 jquery 函数等到加载 iframe 的所有元素?
这是我的代码:
function parsePeopleLink(){
try{
//This is where I check if the wanted I frame already exists
if(document.getElementById('isolatedWorkArea') != null) {
if(window.frames[2] != null) {
if(window.frames[2].name == 'isolatedWorkArea') {
//This is where I want the following code only to be executed when the Iframe's content is fully loaded, otherwise I get an access denied error when trying to change Userlinks
$('#isolatedWorkArea').load(function() {
for( var i = 0; i < window.frames.length; i++){
for(var j = 0; j< window.frames[i].document.frames.length; j++){
IframeDocument = window.frames[i].document.frames[j].document;
changeUserLink(findPeopleIDfix(findPeopleID(IframeDocument)),findUserLinks(IframeDocument),8, IframeDocument);
}
}
});
}
else {
throw e; //I know that all the nested else statements are ugly, I just inserted them for testing purposes
}
}
else {
throw e;
}
}
else {
throw e;
}
}
catch(e) {
//alert(e.description);
for(var k = 0; k < window.frames.length; k++)
{
IframeDocument = window.frames[k].document;
changeUserLink(findPeopleIDfix(findPeopleID(IframeDocument)),findUserLinks(IframeDocument),9, IframeDocument);
iframeindex++;
}
}
}
所有 iframe 都具有:相同的端口、协议和 src。非常感谢帮助