I am trying warn user to save data if he wants leave the page. The message should display simple “Do want save the data?” , If YES call code behind method (asp:button click), if NO leave the page from the page.
But now It is showing Unwanted message string with my message (see below).
var form_has_been_modified = 0;
$(function () {
$("input").keyup(function () {
form_has_been_modified = 1;
})
window.onbeforeunload = function (e) {
if (!form_has_been_modified) {
return;
}
var message = "Do you want to save the data before leave the page?";
return message;
}
});
Unfortunately this is the browser behavior and you cannot change it.
You may want to re-word your message so that it makes sense in the context of the browser’s pre-defined message. Also, make sure you test other browsers, as the message and behavior may be different.