Working with Iframe

Asked

Viewed 223 times

3

How to run the tag:

<iframe src="http://localhost.com/web-p/index2.aspx"></iframe>


Waiting for iframe execution to complete page loading to proceed with other things.

Example:

function onIframeCompleto(){
    alert('o site carregou com sucesso!');
}

2 answers

3


Just use the event onload of iframe.

Example:

function onIframeCompleto() {
  alert('Site terminou de carregar.');
}
<iframe src="http://example.org" onload="onIframeCompleto()"></iframe>

2

Just use the event onload to the iframe.

Take an example:

    window.addEventListener('load', function(){

       var iframe = document.querySelector('iframe'),
           carregar = document.querySelector('#carregar');


        carregar.addEventListener('click', function()
        {
            // mudamos o src do iframe
            iframe.src = 'include.php?' + new Date()
        });

        iframe.addEventListener('load', function(){

            alert('carregou o conteúdo do iframe')
        })
    })

HTML:

 <iframe></iframe>
 <a href="#" id="carregar">Carregar</a>

I made the example by changing the src of iframe through the click event #carregar so that it can become more noticeable at the time of testing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.