onload in iframes not working, if iframe have non-html document in src (pdf or text)

纵然是瞬间 提交于 2019-12-04 00:41:10
Ashirvad

According to the W3C, the iframe tag does not support any event attributes. Although major browsers support it but can not be relied upon. If you really want it try this workaround.You can try something like this.

setTimeout(function(){
    if($('#FrameForPrintVersion').contents().find('*')!='undefined') {
        alert('your frame loaded');
    }
},200)
Don

That's an issue with IE. I'm using following as a solution.

function dodisable() {
    var b1=document.getElementById('B1'); 
    b1.value='Please Wait....'; 
    b1.disabled=true;
    document.getElementById("browse").src = "hhhh.pdf"; /*LINK TO YOUR PDF*/
    setTimeout( URLoader_Timeout, 100);
}

function doenable() {
    var b1=document.getElementById('B1'); 
    b1.value='Submit'; 
    b1.disabled=false;
}

function URLoader_Timeout() { 
    if ( document.getElementById("browse").readyState == "complete")
        doenable();
    else
        setTimeout( URLoader_Timeout ,100);
}

HTML

<input type="button" name="B1" id="B1" value="Go" onclick="dodisable();" />
<iframe id="browse" onload="return  doenable();" style="width:100%;height:100%"></iframe>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!