Re: load event after window.location.replace ?

On 5/31/12 10:51 PM, David Karger wrote:
> The working draft is unclear on the following question: if
> window.location.replace() is invoked, should a "load" event fire when
> the new content arrives?

Yes, it should.

> A quick test
> (http://people.csail.mit.edu/karger/Scrapelet/Dev/testload.html)
> demonstrates that current browsers do *not* fire a load event for the
> replaced content.

Sure they do.  But they're firing it at the new window object that's 
created for the new page, while your event listener is registered on the 
window object for the page being unloaded...

There's a special hack in place for the case when the page being 
unloaded is the initial about:blank that makes the browser reuse the 
window in some cases, which is why the outer DOMContentLoaded in your 
testcase works.

> If that is correct, then how are we supposed to detect
> that the replaced content has finished loading?

Right now, you can't really tell, unless you're replacing something in 
an iframe (in which case you get a load event on the <iframe> element).

-Boris

Received on Friday, 1 June 2012 03:40:06 UTC