Home > front end >  How to judge whether multiple iframe loaded, after the completion of the loading call print window
How to judge whether multiple iframe loaded, after the completion of the loading call print window

Time:02-23

, I used the two methods are as follows: no, but not an error, please leaders see
 
The function print () {
The debugger.
Var iframeLength=document. GetElementsByTagName (" iframe "). The length;
Var iframe_start=0;
$(" iframe ".) each (function () {
Var SRC=https://bbs.csdn.net/topics/$(this). Attr (" SRC ");
$(this) onl oad=function () {
Iframe_start + +;
The console. The info (iframe_start);
If (iframe_start==iframeLength) {
Window. The print ();
}
}
});
}
The function print2 () {
The debugger.
Var iframes=document. GetElementsByTagName (" iframe ");
For (var I=0; I & lt; Iframes. Length; I++) {
Var iframeId=iframes [I]. Id;
Var currentIframe=document. GetElementById (iframeId);
If (currentIframe. AttachEvent) {
CurrentIframe. AttachEvent (onload, function () {
//wait for the iframe loaded
});
continue;
} else {
CurrentIframe. onl oad=function () {
Window. The print ();//the iframe loaded
}
}
}

}

CodePudding user response:

The function print () {
The debugger.
Var iframeLength=document. GetElementsByTagName (" iframe "). The length;
Var iframe_start=0;
$(" iframe ".) each (function () {
Var SRC=https://bbs.csdn.net/topics/$(this). Attr (" SRC ");

/* $(this). Ready (function () {
Iframe_start + +;
The console. The log (iframe_start, 'iframe_start);
If (iframe_start==iframeLength) {
Window. The print ();
}
}) */
//error in jq use ready here
$(this) onl oad=function () {
Iframe_start + +;
The console. The info (iframe_start);
If (iframe_start==iframeLength) {
Window. The print ();
}
}
});
}
  • Related