Solved

No way to find if the browser is closing??

Posted on 2011-03-14
4
335 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now