 <p>I assume that on page load, you are setting up var sncro=1; and when some data changes, you adjust this value. Here is the quick check:</p> <pre><code>window.onbeforeunload = function (evt) { if (sncro != 1) { var message = 'Are you sure you want to leave, cause there are some unsaved changes?'; if (typeof evt == 'undefined') { evt = window.event; } if (evt ) { evt.returnValue = message; } return message; } } </code></pre>