I have the following JavaScript
EDIT: included assignments for changesSaved
var changesSaved = true; $(document).ready(function ()
window.onbeforeunload = function () { var changesSaved = confirm("You havent saved your changes. Are you sure you want to leave the page?"); if (changesSaved) { return true; } else { return false; }