I want to get the confirmation from the user to save a form before page closing with confirm() javascript function. If user pressed Ok button, run save form action and if pressed Cancel button, then close page.
for that I write this :
window.onbeforeunload = function() {
if (confirm('Are you want to save Form ?')){
//saveActions
}
return 'You have unsaved changes!';
}
But onbeforeunload
event for window object does not run confirm() function and jsut it's own confirmation dialog box with string that is next to return instruction.
How can I do that?