遍历iframe,然后加载相应的iframe时,iframe不会是按顺序加载,按我的测试,应该是随机或者并列,
for(var i=0;i<iframe.length;i++){
$("#iframe"+i).load(function(){
i++;
alert(i);
})
}
最终结果:所有的i的长度会是最大值
但是我一定要确定一个iframe都加载完了才能继续执行下一个iframe,所以,
// genaral iframe and log out all sc
function generateFrameAndCloseSCs(){
//it the time goes 10s can't logout,it will enter the redirectLogout()
setTimeout("redirectLogout();",8000);
$.ajax({
url:"<%=Config.getHomeURL()%>/PlugInManageAction.do?operation=getAllDyncMenu",
type:"POST",
dataType:"json",
async:false,
success:function(result){
var SCURLList=result.SC_urlList;
if(SCURLList.length!=0){
var i=0;
loadIframe(i,SCURLList);//travel load frame.
}else{//if it didn't have dync menu ,it will direct into login();
redirectLogout();
}
}
})
}function loadIframe(i,SCURLList){
var iframe = document.createElement("iframe");
iframe.src = SCURLList[i];
iframe.style.display='none';
var length=SCURLList.length;
if(i==length){
redirectLogout();
}else{//核心代码
if (iframe.attachEvent){//IE
iframe.attachEvent("onload", function(){
i++;
loadIframe(i,SCURLList);
});
} else {//not IE
iframe.onload = function(){
i++;
loadIframe(i,SCURLList);
};
}
document.body.appendChild(iframe);
}
}