I am using the window.onbefore unload event on a webpage as follows :
Code:
window.onbeforeunload = confirmExit;
function confirmExit()
{
if (changesMade == 1 && needToConfirm)
{
return "You have not saved changes on this page";
}
}
The function returns a prompt to the user correctly.