//window.onbeforeunload = function(e) { // return 'Are you sure you want to leave this page? You will lose any unsaved data.'; //};
//document.attachEvent("onkeydown", my_onkeydown_handler);
//function my_onkeydown_handler()
//{
// switch (event.keyCode)
// {
// case 116 : // F5;
// event.returnValue = false;
// event.keyCode = 0;
// window.status = "We have disabled F5";
// break;
// }
//}
//window.onbeforeunload = function (e) {
// var message = "Are you sure you want to leave this page? You will lose any unsaved data.",
// e = e || window.event;
// // For IE and Firefox
// if (e) {
// e.returnValue = message;
// //// ACTION
// }
// // For Safari//// ACTION
// return message;
//};
//(function () {
// window.unloader = function(e) {
// (e || window.event).returnValue = null;
// return null;
// };
// window.addEventListener("beforeunload", window.unloader);
//})();
//window.addEventListener("beforeunload", function (event) {
// event.preventDefault();
//});
var popit = true;
window.onbeforeunload = function() {
if(popit == true) {
popit = false;
return "Are you sure you want to leave?";
}
}
//var myEvent = window.attachEvent || window.addEventListener;
//var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable
//myEvent(chkevent, function(e) { // For >=IE7, Chrome, Firefox
// var confirmationMessage = 'Are you sure to leave the page?'; // a space
// (e || window.event).returnValue = confirmationMessage;
// return confirmationMessage;
//});
//window.addEventListener("beforeunload", function (e) {
// var confirmationMessage = "Hi";
// e.returnValue = confirmationMessage; // Gecko, Trident, Chrome 34+
// return confirmationMessage; // Gecko, WebKit, Chrome <34
//});
//$(window).bind("beforeunload",function(event) {
// return "You have some unsaved changes";
//});
//window.onbeforeunload = function (e) {
// e = e || window.event;
// var msg = "Sure you want to leave?";
// // For IE and Firefox prior to version 4
// if (e) {
// e.returnValue = msg;
// }
// // For Safari
// return msg;
//};
//window.onbeforeunload = function(evt) {
// return true;
//}
//window.onbeforeunload = function(evt) {
// var message = 'Are you sure?';
// if (typeof evt == 'undefined') {
// evt = window.event;
// }
// if (evt) {
// evt.returnValue = message;
// }
// return message;
//}
//window.addEventListener('beforeunload', function(event) {
// return 'Are you sure';
//});
//window.onunload = confirmExit;
//function confirmExit() {
// alert("Are you sure you want to leave");
//}
//$(function() {
// $("a").click(function() {
// window.onbeforeunload = null;
// });
// $("input").click(function() {
// window.onbeforeunload = null;
// });
//});
//window.onbeforeunload = function(){
// alert("Are you sure you want to leave");
//}
I have tried all the above codes. They all work well with IE. But none of the codes works with Fire fox and Google Chrome. Can Someone help me out on this. I need to alert the end user with a alert box if he clicks the browsers close button.