第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何檢查iframe是否已加載或是否包含內(nèi)容?

如何檢查iframe是否已加載或是否包含內(nèi)容?

躍然一笑 2019-10-10 14:10:51
我有一個id =“ myIframe”的iframe,這里是我加載其內(nèi)容的代碼:$('#myIframe').attr("src", "my_url");問題是有時加載時間太長,有時加載速度非???。所以我必須使用“ setTimeout”函數(shù):setTimeout(function(){   if (//something shows iframe is loaded or has content)   {       //my code   }   else   {       $('#myIframe').attr("src",""); //stop loading content   }},5000);我唯一想知道的是如何確定是否已加載iFrame或是否包含內(nèi)容。使用iframe.contents().find()將不起作用。我不能用iframe.load(function(){})。
查看完整描述

3 回答

?
滄海一幻覺

TA貢獻(xiàn)1824條經(jīng)驗 獲得超5個贊

嘗試這個。


<script>

function checkIframeLoaded() {

    // Get a handle to the iframe element

    var iframe = document.getElementById('i_frame');

    var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;


    // Check if loading is complete

    if (  iframeDoc.readyState  == 'complete' ) {

        //iframe.contentWindow.alert("Hello");

        iframe.contentWindow.onload = function(){

            alert("I am loaded");

        };

        // The loading is complete, call the function we want executed once the iframe is loaded

        afterLoading();

        return;

    } 


    // If we are here, it is not loaded. Set things up so we check   the status again in 100 milliseconds

    window.setTimeout(checkIframeLoaded, 100);

}


function afterLoading(){

    alert("I am here");

}

</script>


<body onload="checkIframeLoaded();"> 


查看完整回答
反對 回復(fù) 2019-10-10
?
蝴蝶刀刀

TA貢獻(xiàn)1801條經(jīng)驗 獲得超8個贊

請使用:


$('#myIframe').on('load', function(){

    //your code (will be called once iframe is done loading)

});

隨著標(biāo)準(zhǔn)的更改,更新了我的答案。


查看完整回答
反對 回復(fù) 2019-10-10
  • 3 回答
  • 0 關(guān)注
  • 945 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號