Check if the iframe is ready to write

A third party script on my webpage creates an iframe. I need to know when this iframe is ready, so I can manipulate its DOM.

I can think of a hacked approach: I try repeatedly to change the iFrame DOM and return success when we make wands between two attempts. For this, I would prefer a property that I can check on iframes several times.

Is there an alternative internetwork browser approach to understanding iframe is ready? For instance. we can override the onLoad function to be called in our code (but I don’t know if I can do this because I did not create an iframe).

+3
source share
5

jquery?

function callIframe(url, callback) {
    $(document.body).append('<IFRAME id="myId" ...>');
    $('iframe#myId').attr('src', url);

    $('iframe#myId').load(function() 
    {
        callback(this);
    });
}

jQuery.ready iframe

+2

:

var setToLoad = false;

:

function SetToLoad() {
    setToLoad = true;
}

iframe , window.opener

function CallSetToLoad() {
    window.opener.SetToLoad();
}

window.onload = CallSetToLoad;

iframe, , . script.

EDIT:

, script, - :

frames["myiframe"].onload = function()
{
    // do your stuff here
}
+1

iframe? , , iframe iframe, .

0

First: you probably can't manipulate your dom when it loads html from another domain

And you are probably interested in DOMready. Look here: jQuery.ready in a dynamically inserted iframe

0
source

Bilal

There is a document.readyState property that you can check (works in IE).

foo(){
 if([your iframe id].document.readyState != "complete")
 {
   setTimeout("foo()", 500); //wait 500 ms then call foo
 }
 else
 {
   //iframe doc is ready
 }
}

Arkady

0
source

Source: https://habr.com/ru/post/1732928/


All Articles