?
Solved

No way to find if the browser is closing??

Posted on 2011-03-14
4
Medium Priority
?
354 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
[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
4 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 2000 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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