Link to home
Start Free TrialLog in
Avatar of Dattu
DattuFlag for United States of America

asked on

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
Avatar of sdrouins
sdrouins

is this method ok?
<body onBeforeUnload="return 'Quit and lost all data?'">
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!
SOLUTION
Avatar of Badotz
Badotz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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);
        }
    }
}
>>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".
(or something like that ;-)