Solved

Close button of the browser

Posted on 2001-06-15
12
193 Views
Last Modified: 2012-05-04
Hi,
I need to know when the user will click the close button of the browser..
Pls. help
0
Comment
Question by:kulsmadya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +5
12 Comments
 
LVL 8

Expert Comment

by:edemcs
ID: 6196081
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.
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6196119
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.
0
 

Author Comment

by:kulsmadya
ID: 6196131
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.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 10

Expert Comment

by:dij8
ID: 6196171
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.
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6196226
It is not possible ..........
0
 

Author Comment

by:kulsmadya
ID: 6196244
so what would be the work arround??
0
 
LVL 10

Expert Comment

by:dij8
ID: 6196276
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.
0
 
LVL 8

Accepted Solution

by:
edemcs earned 200 total points
ID: 6196359
Here is the solution:

<body onLoad="closing=true" onUnload="if (closing) window.open('thanksForVisiting.html','newwin');">

<a href="nextpage.htm" onClick="closing=false">Click to go to another page..</a>

When links are clicked, set the closing variable = false.  If a link isn't clicked and the page unloads, that probably means that the user is closing the browser!  This should definitely work.

Hope this helps!
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6196917
0
 

Expert Comment

by:kamcheungon
ID: 6209020
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>



0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6833207
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.
http://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.
http://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.

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

 
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6891296
Force-accepted by
Netminder
CS Moderator
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question