Bug 18341 - window.onunload not fired when the last browser window is being closed
Summary: window.onunload not fired when the last browser window is being closed
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 525.x (Safari 3.1)
Hardware: PC Windows Vista
: P2 Major
Assignee: Nobody
Keywords: InRadar, PlatformOnly
Depends on:
Reported: 2008-04-07 06:35 PDT by ptr
Modified: 2008-07-09 14:32 PDT (History)
2 users (show)

See Also:

Testcase for window.onunload bug (454 bytes, text/html)
2008-04-07 06:38 PDT, ptr
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description ptr 2008-04-07 06:35:13 PDT
We expected that the handler attached to "window.onunload" gets invoked anytime when a document gets unloaded - means for any of following cases you should get same and consistent behavior.

(A) Close last browser window
(B) Close window, but still have another opened
(C) Refresh window
(D) Reload window/ put another URL in address bar

Wrong behavior with Safari 3.1. (525.31.3) [WinXP/SP2]
Safari-for-Windows doesn't cover the case (A). When the LAST browser window is being closed, the handler attached to "window.onuload" is not called. Using attached sample, you will not get any alert or window opened for the case (A) at all. The cases (B,C,D) are handled properly. 

Expected behavior
MSIE, Firefox or even Safari for Mac 3.1 behaves correctly,
in all cases (A,B,C,C) new window and popup gets displayed.

Note:  Even the scenario may look strange for you - we use the 
window.onuload to perform reasonable actions (to notify backend servers 
about to close backend sessions when the user left the browser), so it 
is not about just annoying popups/windows, but have strong real and valid 
usecase. I put the severity to Critical as it is almost a blocker for our apps.

Can be related to:
* http://bugs.webkit.org/show_bug.cgi?id=12469
Comment 1 ptr 2008-04-07 06:38:00 PDT
Created attachment 20380 [details]
Testcase for window.onunload bug

Refresh, reload or close browser window and observe whether the browser is performing onunload actions or not. You should see a new new window and alert displayed.
Comment 2 ptr 2008-04-07 06:57:46 PDT
As the testcase opens new window, make sure you disabled popup blocker before you start testing.  (or comment out the "window.open" line completly, stay only with window.alert).  
Comment 3 mitz 2008-04-07 08:16:17 PDT
Comment 4 David Kilzer (:ddkilzer) 2008-06-01 08:51:10 PDT
See Bug 12469.

Comment 5 Adele Peterson 2008-07-09 14:32:14 PDT
Seems to be fixed in TOT.  Please let us know if it still doesn't work for you.