I want to warn user before closing page, but only if the page is processing or uploading its data to the server. Its asp.net web application. I have used onbeforeunload javascript event to show the message, but it seems to be not fitting in my scenario.
$(document).ready(function () { $('.saveButton').click(function () { window.btnClicked = true; }); }); function closeEditorWarning() { if (window.btnClicked) { return 'It looks like you have been uploading something -- if you leave before submitting your changes will be lost.' } }
Can you put your code for how you are calling closeEditorWarning(). Anyway I tried this on similar lines and it is working -
$(document).ready(function(){
$("#save").click(function(){ window.btnClicked = true; }
);
});
window.onbeforeunload = function(e){
if(window.btnClicked)
return "Are you sure, you want to leave?";
}
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.