How to tell when an HTMLview is finished loading?

Is there a way to tell when an HTMLview has finished loading? I’m displaying pdf’s in an iframe and I’d like to run a waitcursor until they are done loading…

simplified code looks like:

HTMLview1.innerhtml =

Thanks!

Nate

Hi Nate,

I think the answer may be yes and no. Here’s some code that can be replaced/inserted into the HTMLview sample project to see the effect:

Function Button4_onclick()
  HTMLview1.innerHTML="<iframe src='year.pdf' width=310 height=260 onload=FrameIsLoaded()></iframe>"
  HTMLview1.refresh()  
End Function

Function FrameIsLoaded()
  console.log("The iframe is loaded")
  $("#HTMLview1 embed").on("load", DocIsLoaded)
End Function

Function DocIsLoaded()
  console.log("The pdf is loaded")  
End Function

It’s easy enough to add a listener to the iframe to detect when it has loaded. The console records the moment the iframe has content and the PDF begins to load. For all content types except PDFs, this may be enough.

But the listener I’ve placed on the embed tag never fires. I’ve read that it’s actually not possible to determine when a PDF has finished loading in an iframe but it seems like it should be.

Of course, the listener has to be created after the element is created otherwise it won’t work, which is why I placed the embed tag listener where I did. But I must still be doing something wrong.

Anyway, I post this in the hopes that you or someone else may see something there that would lead to a solution.

Kind regards,
Doug

Thanks for that Doug. My poking around has turned up basically the same thing, but I hadn’t seen the embed tag tried–stinks that it doesn’t work.

The issue I’m running into is I’m turning on a waitcursor overlay on the app while the app fetches a pdf stored on the device, but because of the behavior your describe (i.e. the onload function firing at the beginning of when content gets loaded into an iframe) the waitcursor overlay gets turned off early and often my users are going to be looking at a blank iframe for about a second before the pdf actually displays. Annoying.

Let me know if you turn up anything that works and I’ll do the same.

Nate