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
DattuAsked:
Who is Participating?
 
sdrouinsConnect With a Mentor Commented:
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
 
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
BadotzConnect With a Mentor Commented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.