Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have iframe with onload handler:

<iframe id="FrameForPrintVersion" src="" border="0" style="height:0; width:0; visibility:hidden;" onload = 'frameOnload()' >

It works fine if i use html-pages as the source of the iframe, but not when i set src to any pdf document. Is it posible to handle when a PDF document was loaded in this case?

like image 387
aiiak Avatar asked Aug 22 '12 15:08

aiiak


People also ask

Why is my iframe not working?

If the primary domain for your website is secure with SSL (https://) but the source URL for your Iframe is not, your website will display an error, or simply not display the content. To fix this, you'll need to update the Source URL for your Iframe content with the secure (https://) version.

Does iframe need SRC?

No, it is not valid to specify an empty iframe src. # is meant to be a reference to an anchor within the current page (or, often used as a routing scheme when working with AJAX requests).

Will iframe work if JavaScript is disabled?

If a user has javascript disabled, iframes will work. An iframe tag has attributes “height” and “width,” which allows the designer great latitude with dimensions and format like 300×250 , 728×90 depending on the Ad size. Iframe tag can appear anywhere on the page and several iframes can be added if wished to.


2 Answers

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)
like image 60
Ashirvad Avatar answered Sep 21 '22 18:09

Ashirvad


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>
like image 27
Don Srinath Avatar answered Sep 20 '22 18:09

Don Srinath