473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

close user from site with clicking close button of browser

oranoos3000
107 100+
hi
i,m writing a script for chat room
i,d like to with clicking close button of browser user is exited from site
meaning of this say is with clicking close button all of session variable
is removed from server
i wrote below code for this action
but sorry i failed
please help me
my base page code is as follows
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $_SESSION['username']='sima';
  4. ?>
  5. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  6. <html>
  7. <head>
  8. <title>Untitled Document</title>
  9. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  10. <script type="text/javascript">
  11. function getData(source)
  12. {<!--119-->
  13.     var XMLHttpRequestObj=false;
  14.     if(window.XMLHttpRequest)
  15.     {    XMLHttpRequestObj=new XMLHttpRequest();}
  16.     else if(window.ActiveXObject)
  17.     {    XMLHttpRequestObj=new ActiveXObject("Microsof.XMLHTTP");}
  18.  
  19.     if(XMLHttpRequestObj)
  20.     {<!--131-->
  21.         XMLHttpRequestObj.open("GET",source);
  22.         XMLHttpRequestObj.onreadystatechange=function()
  23.         {<!--135-->
  24.             if(XMLHttpRequestObj.readyState==4 && (XMLHttpRequestObj.status==200 || XMLHttpRequestObj.status==0))
  25.             {<!--137-->
  26.             newWindow=window.open("show_users.php","new users");
  27.             newWindow.focus();
  28.             }<!--e137-->
  29.         }<!--e135-->
  30.     }<!--e131-->
  31.         XMLHttpRequestObj.send(null);
  32. }<!--e119-->
  33.  
  34. </script>
  35. </head>
  36.  
  37. <body onUnload="getData('exit.php');">
  38.  
  39. </body>
  40. </html>
  41.  
  42.  
code of exit.php is as follows
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. session_destroy();
  4. ?>
  5.  
Jan 9 '10 #1
1 1599
Dormilich
8,658 Expert Mod 8TB
have you tried window.onbeforeunload?
Jan 9 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: feng | last post by:
Hi, In our asp.net app, we need to capture the event when user close the browser window by clicking on the "x" button. But it doesn't seem to be as easy as it sound. Can someone show me how to...
20
by: Harry | last post by:
My development environment is Framework 1.1, ASP.Net and IE 6.X. I have logout button in all the screens in the application. I am doing database activity when the user clicks on logout button....
1
by: RJN | last post by:
Hi I have a pop-up window which has a task menu on its left which are nothing but links to different screens. This window also has a close button. On click of close button I do some server side...
3
by: Lord2702 | last post by:
Sat. Oct. 30, 2004 3:25 PM PT I want to detect, if user has close the browser, (after logging to my site), that user has closed the browser. How to achieve it ? I want to know this close action...
0
by: Vam$y | last post by:
In asp.net how to catch window close event when a user closes the window explicitly by clicking on “x” button which is on the right top corner of the browser. My requirement is When a user...
0
by: JP | last post by:
Is there a way to temporirly disable the X button (close) on a MODAL window in the web browser? We have cleanup code that needs to run after the user closes the modal window. This works fine if the...
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
7
by: Toccoa | last post by:
After considerable googling - I mean searching with Google(r) - I could not find javascript on a button or <a href=... to close a window in the latest versions of IE and FireFox. There seemed...
15
by: =?Utf-8?B?QmVuamFtaW4gSmFuZWNrZQ==?= | last post by:
Hi, we're struggling with a strange session problem in an ASP.NET 2.0 application. The application is used by our customers to access customer-related information such as invoices over the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.