[英]Better way to find all iframes on the page
I am developing iPad application in that more than 6 iframes are available. 我正在开发iPad应用程序,因为可以使用6个以上的iframe。 After fully loaded the page, the page scroll went to the some where in the middle.
页面完全加载后,页面滚动到中间的某个位置。 So I decided to get page scrolltop written JavaScript code like this:
所以我决定让页面scrolltop编写如下JavaScript代码:
$(document).ready(function() {
try {
var iframecompleted = [];
$("iframe[id*='iframe']").each(function(eli, el) {
$(this).bind("load", iframeinit);
});
function iframeinit() {
iframecompleted.push($(this).id);
$(this).unbind("load", iframeinit);
}
var timer = setInterval(function() {
if ($("iframe[id*='iframe']").length == iframecompleted.length) {
clearInterval(timer);
$('html, body').animate({
scrollTop: 0
}, 500);
if (FrameID != "") {
var j = 0;
var ss = FrameID.split(",")
for (j = 0; j < ss.length; j++) {
var collPanel = $find("pane" + ss[j]);
if (collPanel != null)
collPanel.set_Collapsed(true);
}
FrameID = "";
}
}
}, 10);
}
catch (e) {
alert(e);
}
});
}
I would like to find a better way to achieve this task. 我想找到一种更好的方法来完成此任务。 Your ideas are more welcome.
欢迎您提出您的想法。
You could do something like this : 您可以这样做:
var count = 0;
$("iframe").load(function() {
if (++count === 6)
{
alert("TODO: All the frames are loaded, do you stuff");
}
});
You can do something like this: 您可以执行以下操作:
var count = $('iframe').length; $(function() { $('iframe').load(function() { count--; if (count == 0) alert('all frames loaded'); }); });
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.