Confirmation before closing of tab/browser
Try this:
<script>
window.onbeforeunload = function (e) {
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Sure?';
}
// For Safari
return 'Sure?';
};
</script>
Here is a working jsFiddle
Try this:
<script>
window.onbeforeunload = function(e) {
return 'Dialog text here.';
};
</script>
more info here MDN.