I want to show a confirm box when a user tries to reload a page. I have tried it in my project and it did not work. I have created a sample code of what i have tried and even it is not working. Can anybody tell where i have gone wrong. I am not even getting the confirm box. I am using Chrome 33+. I need to execute some code in the window.onbeforeunload before the box pops up.
<!DOCTYPE>
<html>
<body>
<script type="text/javascript">
window.onbeforeunload = function()
{
var r = confirm("Are you sure you want to reload the page.");
if(r)
{
window.location.reload();
}
else
{
}
};
</script>
</body>
</html>