Working with Iframe

3

How to run the tag:

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


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

Example:

function onIframeCompleto(){
    alert('o site carregou com sucesso!');
}
    
asked by anonymous 20.02.2015 / 19:20

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>
    
20.02.2015 / 19:34
2

Just use the onload event for iframe .

See 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 the iframe later through the click event in #carregar so that it can be more noticeable at the time of testing.

    
20.02.2015 / 19:35