Window beforeunload shows two dialogs
I have this jQuery code;
$(function () {
$(window).unbind("beforeunload");
$(window).bind("beforeunload", function () {
return confirm("Really?");
});
});
When i close my window I get the confirmation request and if I hit "Cancel" I get a second confirmation which says;
"Are you sure you want to navigate away from this page?"
"False"
"Press OK to continue, or Cancel to stay on the current page."
Why am I getting a second dialog and is there a way to remove it?
edit
开发者_Go百科have changed the code to be;
$(function () {
$(window).bind("beforeunload", function () {
return "slappy?";
});
});
But the confirmation message does not appear. The event is firing because I can put an alert in there and see the alert.
edit 2
Have changed the code to this;
window.onbeforeunload = function () {
var txtBlog = $('#tbxNote').val();
if (txtBlog != "")
return "You have not saved your blog entry.";
}
it works but there is other text above and below my message;
"Are you sure you want to navigate away from this page?"
"You have not saved your blog entry."
"Press OK to continue, or Cancel to stay on the current page."
Just use:
return "Really?";
The beforeunload event requires you to return a string containing the message you want displayed in the standard "Are you sure" dialog.
精彩评论