遍曆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){//IEiframe.attachEvent("onload", function(){i++;loadIframe(i,SCURLList);});} else {//not IEiframe.onload = function(){i++;loadIframe(i,SCURLList);};}document.body.appendChild(iframe); } }