Exactly when does an IFRAME onload event fire?

后端 未结 3 1192
逝去的感伤
逝去的感伤 2021-02-12 11:42

Does the IFRAME\'s onload event fire when the HTML has fully downloaded, or only when all dependent elements load as well? (css/js/img)

3条回答
  •  被撕碎了的回忆
    2021-02-12 12:20

    The above answer (using onload event) is correct, however in certain cases this seems to misbehave. Especially when dynamically generating a print template for web-content.

    I try to print certain contents of a page by creating a dynamic iframe and printing it. If it contains images i cant get it to fire when the images are loaded. It always fires too soon when the images are still loading resulting in a incomplete print:

    function printElement(jqElement){
        if (!$("#printframe").length){
            $("body").append('