Solved

No way to find if the browser is closing??

Posted on 2011-03-14
4
340 Views
Last Modified: 2012-05-11
I come from the desktop application space and find it shocking that I can not easily determine that the browser is closing. I have tried using JavaScript and catching the onunload and beforeunload events but find they fire regardless of what the user has done on the page, including clicking the Close button in the upper right corner of the window.

That seems so foreign to me.

Isn't there a way? Isn't there an addition test I could do in JavaScript to test if the browser is still open?

100% of my users will be on Windows.  Can't I read the ProcessID when the page loads, then I detect an onunload event start a timer that will fire in 30 seconds. When that timer fires it will check if the ProcessID still exists and if not, the page has closed.

I don't know if that could ever work but I am trying to get your mental juices flowing about what I could do if I really really wanted to be notified when the browsers has closed. And to demonstrate I am willing to be a little unconventional about how I accomplish this.

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 2
  • 2
4 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 500 total points
ID: 35128450
Ah this old chestnut again. Do a quick search of EE and you will find endless debates about this question.

The simple answer is, unforunately, no. The major difference between a desktop application and a browser based application is that in a web application you don't own the window that your app is in. The browser is a security restricted sandbox in which your page is allowed to operate, you can't check process IDs because you have no direct access to the OS.
0
 

Author Comment

by:newbieweb
ID: 35128656
But isn't there a way to inspect the sender object? Does the X box on the browser give a different value for sender versus an HTML button?

Or using Alt+F4?

Is there no back door method I could devise? Is there any information anywhere that's changed which I could inspect for changes?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35128773
There is no "sender" because closing the window doesn't raise any server-side events, in the same way you don't get any server-side events if the user simply navigates to another site.

The Session_End event will tell you that there has been no activity from the user for a period of time, but the browser will not actively tell you that it is leaving your site.

You can try reading this:

     http://forums.devarticles.com/javascript-development-22/how-to-stop-browser-from-closing-using-javascript-8458.html

But as with all of these solutions they will not cover all cases.
0
 

Author Closing Comment

by:newbieweb
ID: 35128802
Thanks, I'll dig into this.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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