when user click a another link or refresh the page, the window will unload, how to prevent/confirm it?
+2
A:
I think the onbeforeunload event handler would be what you're looking for.
Try the following:
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
Erik
2010-01-08 17:27:48
thank you ......
lovespring
2010-01-08 17:31:40
+3
A:
From here http://bytes.com/topic/javascript/insights/825556-using-onbeforeunload-javascript-event
<script type="text/javascript">
window.onbeforeunload = function(){ return 'Your Returned String Goes Here';}
</script>
Daniel A. White
2010-01-08 17:27:52
Can you add some content to this answer please? Imagine links didn't exist, how useful would this be?
Jonathan Sampson
2010-01-08 17:30:51
@Jonathan Sampson - Good point. I'll do that next time. I'd update this answer, but the accepted one is basically the same.
Topher Fangio
2010-01-08 18:46:08