Link to home
Start Free TrialLog in
Avatar of kulsmadya
kulsmadya

asked on

Close button of the browser

Hi,
I need to know when the user will click the close button of the browser..
Pls. help
Avatar of edemcs
edemcs
Flag of United States of America image

what specifically for?  If you want to run a function when the page is unloaded, you could you the OnUnload attribute in the Body tag.
But remember OnUnload event is called the user closes the browser as well as when the page is refreshed  or the user moves to another page leaving the current page.
Avatar of kulsmadya
kulsmadya

ASKER

I need to call the function when the user will click close button of the browser.

scenario is: if the user is logged in into the website. & if he doesnt logout & clicks the close button of the browser, i need to trap the event.
It can't be done.  The only option is onunload.  And that is not what you are after.

Closing the browser (all instances) will kill any sessions so that may solve the problem you have regarding logging out.
It is not possible ..........
so what would be the work arround??
Educate the people using your site to use the log-out button that you also include in your page.  And that is the ONLY solution.
ASKER CERTIFIED SOLUTION
Avatar of edemcs
edemcs
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
Another alternative, works with older browser:

In your main window:
<html>
<head>
<title></title>
<script>
<!--
var WinMon;

function OpenMonitor () {
     WinMon = window.open ('monitor.html','monitor','width=100,height=100');
     WinMon.opener = window;
     
     WinMon.OpenerAlert ();
}

function OpenerCheck () {
     alert (self.screenTop);
     if (WinMon) {
          WinMon.OpenerAlert ();
     }
}
//-->
</script>
</head>
<body onLoad="OpenMonitor ()" onUnload="OpenerCheck ();">
</body>
</html>


In the pop up "monitor.html":
<html>
<head>
<title></title>
<script>
<!--
var TimeoutID;
function CheckOpener () {
     if (opener.closed) {
          alert ("Opener is Closed");
          clearTimeout (TimeoutID);
     }
}

function OpenerAlert () {
     TimeoutID = setTimeout ("CheckOpener()", 100);
}
//-->
</script>
</head>
<body>
</body>
</html>



This question appears to have been abandoned. All your open questions today are at the bottom.   Your options are:
 
1.  Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3.  Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4.  Delete the question. Again, you must tell the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below, include the question QID/link.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this Help Desk link for Member Guidelines, Member Agreement and the Question/Answer process:  Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues.
https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp


PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:
 
Please leave any comments regarding this question here on closing recommendations if this item remains inactive another three days.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
 
P.S.  For year 2000 question, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.

--------------------------------------------------------------------------------------------------------------------------
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11853299
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20118299
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20136303
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20136304
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20144419

 
Force-accepted by
Netminder
CS Moderator