Bug 21699

Summary: onbeforeunload/onunload should fire on frames/iframes
Product: WebKit Reporter: Ojan Vafai <ojan>
Component: WebCore JavaScriptAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: ap, bedney, dpopa, oliver, ted
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
reduced testcase none

Description Ojan Vafai 2008-10-16 18:10:21 PDT
Testcase coming.
Comment 1 Ojan Vafai 2008-10-16 18:33:11 PDT
Created attachment 24449 [details]
reduced testcase

page with an iframe that has an onbeforeunload handler. attempting to leave the page should popup the beforeunload dialog.
Comment 2 Ted Rust 2008-11-08 17:14:51 PST
This looks like a duplicate of bug #19418.
Comment 3 Alexey Proskuryakov 2008-11-11 02:44:41 PST
See also: bug 15652.
Comment 4 Alexey Proskuryakov 2008-11-15 02:22:37 PST
Confirmed with r38387.

In bug #19418, the handler is installed on the body of iframe document, while here, it is installed on Window object. So, these bugs are not exact duplicates, keeping them separate for now.
Comment 5 Alexey Proskuryakov 2008-11-15 02:29:51 PST
Note however that fixing this may give a way to ads in iframes to be even more nasty than they are now, and open windows when navigating away from a page with an ad. They could be other undesirable consequences, as well.
Comment 6 Dan POPA 2009-04-29 02:48:59 PDT
(In reply to comment #5)
> Note however that fixing this may give a way to ads in iframes to be even more
> nasty than they are now, and open windows when navigating away from a page with
> an ad. They could be other undesirable consequences, as well.
> 

From your argument I can see you are against people having guns, because, you say, some will start shooting other people.

The beforeunload event could be abused in the same way as the unload event.

People already have methods of killing other people.

If the beforeunload event does not trigger for iframes, developers have no way of stopping a navigation inside an IFRAME so the user will not have a chance to save their work.

I'm not saying having guns is a good thing, I'm just saying that the beforeunload is really useful.
Comment 7 Maciej Stachowiak 2009-06-16 14:58:42 PDT
I'm told (though I haven't tested) that IE and Firefox allow this. The HTML5 spec also describes beforeunload in some detail.
Comment 8 William J. Edney 2009-06-16 15:10:13 PDT
Maciej -

Yes, I know for a fact that IE and FF allow this, because I use it all day, every day.

For Webkit-based browsers, I had to play major workaround games to get this to work.

Cheers,

- Bill
Comment 9 Oliver Hunt 2009-07-16 02:40:08 PDT

*** This bug has been marked as a duplicate of bug 19418 ***