Solved

No way to find if the browser is closing??

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 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