window.onbeforeunload = function(e) { var e = e || window.event; // For IE and Firefox prior to version 4 if (e) { e.returnValue = "Any string"; } // For Safari return "Any string"; };