• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

shpwing alert when closing the browser using right side top 'X' button

Hi,
I need to display a box do you want to continue closing the button and loose all the information when an user click on close X button
0
Dattu
Asked:
Dattu
  • 5
  • 2
2 Solutions
 
sdrouinsCommented:
is this method ok?
<body onBeforeUnload="return 'Quit and lost all data?'">
0
 
BadotzCommented:
Might not be OK in Firefox, BUT...you can add a method to the "window" object:

window.onbeforeunload = function(msg){
    return confirm(msg);
}

NOTE: I have not tested this, and for practical reasons you may want to make sure there is no "onbeforeunload" event in whatever browser you are in BEFORE YOU BLINDLY DO ANYTHING LIKE THIS!
0
 
BadotzCommented:
Something like:

if (document.all) { // IE family
    if (!window.onbeforeunload) { // Make sure the event is not defined
        window.onbeforeunload = function(msg){
            return confirm(msg);
        }
    }
}

"msg" is the message you want to display.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sdrouinsCommented:
window.onbeforeunload = function(msg){
    return confirm(msg);
}
is the same result of putting il on the body tag......

and YES  the onbeforeUnload is IE only...
0
 
BadotzCommented:
Sorry, you only want to do this for NON-IE browsers:

if (!document.all) { // Not of the IE family
    if (!window.onbeforeunload) { // Make sure the event is not defined
        window.onbeforeunload = function(msg){
            return confirm(msg);
        }
    }
}
0
 
BadotzCommented:
>>is the same result of putting il on the body tag......

No, it is not. My example clearly and cleanly removes JavaScript from the HTML code. Further, multiple events can be invoked easily.

The French call it "mise en place", and it means "everything is where they are supposed to be".
0
 
BadotzCommented:
(or something like that ;-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now