Determining when contents of an IFrame has loaded

2019-07-29 22:18发布

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 ?

1条回答
我想做一个坏孩纸
2楼-- · 2019-07-29 22:59

Use onload event of iframe.Simple

<iframe src="test.pdf" onload="alert('Worked')" ></iframe>
查看更多
登录 后发表回答