How do I check if an iframe has loaded completely

3

So, I'm producing a site where I'm using iframes with other sites within it, see the image below:

Code:

<iframewidth="100%" height="747px" src="www.site.com" id="iPrincipal" scrolling='no' frameborder="0" allowfullscreen="true">

But the point is that it takes a few seconds to fully load the iframe / other site, so I wanted to know a way to identify if it was fully loaded. For example, an alert: 'iframe has been fully loaded'.

Thank you very much:)

    
asked by anonymous 07.02.2016 / 22:04

1 answer

2

Hello, just you for a window.load on the iframe page, type this

On the page where the

<iframe src="SeuIframe.html">

Put the code below inside the

 <script type="text/javascript">
        function carregado(msg){ alert(msg) }
    </script>

Already on the SeuIframe.html page, put this:

   <script type="text/javascript">
        window.onload = function(){
            parent.carregado("Página 100% carregado.")
        }
    </script>
    
07.02.2016 / 22:58