Solved

No way to find if the browser is closing??

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
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.

744 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

15 Experts available now in Live!

Get 1:1 Help Now