onbeforeunload return value stopped working

2,381 views
Skip to first unread message

Shachar Zohar

unread,
Mar 4, 2014, 2:09:25 PM3/4/14
to chromi...@chromium.org
Anyone noticed that returning a value from the onbeforeunload callback doesn't prompt a box to the user anymore? (from Chrome 34+)

window.onbeforeunload = function(){return "are you sure?"};

Is there a workaround? is this on purpose?

Thanks,
Shachar

Charlie Reis

unread,
Mar 4, 2014, 2:16:15 PM3/4/14
to shac...@gmail.com, chromium-dev
It works for me on the 35.0.1871.0 canary.  If you have more specific repro steps to show the problem, please file a bug at crbug.com.

Charlie


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Robert Flack

unread,
Mar 4, 2014, 2:18:16 PM3/4/14
to cr...@chromium.org, shac...@gmail.com, chromium-dev
Your example is missing a call to the confirm function:

window.onbeforeunload = function(){return confirm("are you sure?")};

The "Enable fast tab/window close" flag (chrome://flags/#enable-fast-unload) will likely break this, but it is working for me without this flag on Chrome 35 canary as well.

Charlie Reis

unread,
Mar 4, 2014, 2:19:21 PM3/4/14
to Robert Flack, shac...@gmail.com, chromium-dev
Robert: no confirm call is needed for beforeunload.  The string is supposed to be displayed in the beforeunload dialog.

Charlie

Robert Flack

unread,
Mar 4, 2014, 2:22:41 PM3/4/14
to Charlie Reis, shac...@gmail.com, chromium-dev
My mistake, it works without the confirm for me as well. If not working for you please do file an issue with the particular chrome version and platform.

Shachar Zohar

unread,
Mar 6, 2014, 3:30:43 AM3/6/14
to Robert Flack, Charlie Reis, chromium-dev
Just verifying with you guys before I'm opening the bug, it happens with addEventListener:

David Benjamin

unread,
Mar 6, 2014, 10:11:36 AM3/6/14
to shac...@gmail.com, Robert Flack, Charlie Reis, chromium-dev
Have you tried that in other browsers? As far as I know, return values in addEventListener aren't supposed to do anything. The addEventListener version is

window.addEventListener("beforeunload", function(ev) {
  ev.returnValue = "Blah blah blah";
});


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

Shachar Zohar

unread,
Mar 6, 2014, 10:31:26 AM3/6/14
to David Benjamin, Robert Flack, Charlie Reis, chromium-dev
Well, it worked with chrome so far (33) and since 34 it stopped working

Erik Arvidsson

unread,
Mar 7, 2014, 12:34:33 PM3/7/14
to shac...@gmail.com, David Benjamin, Robert Flack, Charlie Reis, chromium-dev
That is an intentional change to match the spec and other browsers.

erik


Shachar Zohar

unread,
Mar 9, 2014, 4:54:40 AM3/9/14
to Erik Arvidsson, David Benjamin, Robert Flack, Charlie Reis, chromium-dev
If I understand correctly, addEventListener doesn't propogate the return value to the browser's algorithm that handles that return value, opposed to onEvent = function(){return value} ?
Reply all
Reply to author
Forward
0 new messages