How do I check if an iframe has fully loaded

Asked

Viewed 1,245 times

3

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

inserir a descrição da imagem aqui

Code:

<iframe width="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 iframe/another site, so I wanted to know a way to identify if it was fully loaded. For example, an alert: 'iframe has been fully loaded'.

Thanks in advance :)

  • Well, you said it didn’t work. First of all, I advise next time to comment on my answer to avoid problems. But returning to the subject, could you put in this your post (editing it) the content within the <head> tags of the respective sites? I assure you that the code I passed on works, and I would be delighted if I could set it up for you.

1 answer

2

Hello, just put a window.load on the iframe page, like this

On the page containing the

<iframe src="SeuIframe.html">

Put the code below inside the tag

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

Already in the page of Seuiframe.html, put this:

   <script type="text/javascript">
        window.onload = function(){
            parent.carregado("Página 100% carregado.")
        }
    </script>
  • well... it didn’t work. Like, I’m not doing this operation between html files. from the same site, I am using different domains, that is: they are two sites. Let’s say I have a main site: www.siteprincipal.com! And of course, iframe will "reproduce" the other site: www.othosite.com, got it? kk I think this check that I am trying to do is impossible, the only way would be to put a text "Loading iframe..." and make it appear after a certain time (using a timer and the function style.display)

Browser other questions tagged

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