Bug 20135 - onbeforeunload doesn't work when set with addEventListener
Summary: onbeforeunload doesn't work when set with addEventListener
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-22 14:33 PDT by Ojan Vafai
Modified: 2017-02-19 18:39 PST (History)
6 users (show)

See Also:


Attachments
testcase that works in IE/FF but fails in WebKit (439 bytes, text/html)
2008-07-22 14:34 PDT, Ojan Vafai
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ojan Vafai 2008-07-22 14:33:21 PDT
window.addEventListener('beforeunload', function(e) {
  (e || window.event).returnValue = "wot?";
  return "wot?";
}, true);

This should popup a dialog asking if I want to leave the page when I try to navigate away. In WebKit, it only seems to do so if I set the handler using window.onbeforeunload.
Comment 1 Ojan Vafai 2008-07-22 14:34:40 PDT
Created attachment 22434 [details]
testcase that works in IE/FF but fails in WebKit

You should see an onbeforeunload dialog, followed by an alert in the onunload handler. In WebKit, you only see the alert from the onunload handler.
Comment 2 Alexey Proskuryakov 2008-11-10 22:56:27 PST
Confirmed with r38249 on Mac OS X.
Comment 3 Dmitry Titov 2009-11-10 15:51:57 PST
This is fixed by the recent changes to EventTarget that unified addEventListeners and event attributes. Works with r 50777 on Mac OS X.
It'd be good to have a test though.