1

NB: I don't believe this is a duplicate of Detect failure to load contents of an iframe or Detecting when Iframe content has loaded (Cross browser) (or any of the similar ones).

In short I'm using an IFrame to display Pdfs using the browsers' internal viewer. Since we only support Chrome/FF (we use WebGL) and both have an embedded Pdf viewer, it's a convenient way to avoid implementing pdf.js (at least until we need more control / can spare the resource).

That said, we do want to be able to detect when the IFrame has finished loading so we can transition properly/detect problems.

So, assuming the IFrame source is a pdf (and the pdf is coming from the same domain), is there any way to determine when the iframe has loaded from the outside ?

Community
  • 1
  • 1
Basic
  • 26,321
  • 24
  • 115
  • 201

1 Answers1

3

Use onload event of iframe.Simple

<iframe src="test.pdf" onload="alert('Worked')" ></iframe>
bugwheels94
  • 30,681
  • 3
  • 39
  • 60
  • 2
    Obviously - that's what I was doing. There's a slight issue in the onload fires twice - once when the iframe element is added to the DOM, the second time when the actual contents are loaded (probably a side-effect of setting the src later using Js) but I can work around that by binding the handler later. Thanks – Basic Jun 27 '13 at 11:36