I'm wondering if can I change the window.beforeunload
message. All examples on the internet are similar to this:
$(window).bind('beforeunload', function() {
return 'You have unsaved changes. If you leave the page these changes will be lost.';
});
That's cool, and in Google Chrome my message will be displayed, but in Firefox the default message is displayed. How can i trick Firefox to display my message and not the default message?
I'm wondering if can I change the window.beforeunload
message. All examples on the internet are similar to this:
$(window).bind('beforeunload', function() {
return 'You have unsaved changes. If you leave the page these changes will be lost.';
});
That's cool, and in Google Chrome my message will be displayed, but in Firefox the default message is displayed. How can i trick Firefox to display my message and not the default message?
Share Improve this question edited Feb 8, 2013 at 15:52 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Feb 8, 2013 at 13:13 SoraSora 2,55119 gold badges77 silver badges151 bronze badges 4-
1
Firefox (version 4+) doesn't support custom messages on
onbeforeunload
anymore. bugzilla.mozilla/show_bug.cgi?id=588292 – gen_Eric Commented Feb 8, 2013 at 15:45 - 1 @RocketHazmat you might want to add that as an answer. For points and whatnot. Update: I see you have 50k points, you probably already know how this works. Disregard. – Felix Commented Feb 8, 2013 at 15:57
- @Felix: Sometimes when answers are just "you can't" or "that's how it works", I don't feel like typing an entire answer :-P Alas, I added one anyway :-) – gen_Eric Commented Feb 8, 2013 at 16:15
-
Chrome no longer displays the custom message returned from
beforeunload
. chromestatus./feature/5349061406228480 – jimp Commented Jun 20, 2017 at 23:01
1 Answer
Reset to default 6onbeforeunload
is a weird event. Browsers have been debating what to do with it for a while.
- IE and Chrome will display your message in the dialog along with their own message.
- Firefox used to display your message, but in version 4+, they stopped supporting custom messages. See this: https://bugzilla.mozilla/show_bug.cgi?id=588292
- Opera doesn't even support the
onbeforeunload
method!
This method is under debate because it can be used for evil, and also because it can confuse/annoy users. Scammy, virus-laden sites can use messages like:
"Leaving the page will mean your puter may still be infected, please stay and install our virus scanner"
Nowadays, websites can use AJAX / localStorage to save changes, so this event isn't really needed.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745250156a4618629.html
评论列表(0条)