473,471 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Detect window close and navigating away from a page

Hello,

I've been trying to detect when a user closes a page or navigates away
from it. This is part of a solution for locking pages (that is, if a
user enters a page, no one else can enter it while he doesn't leave).
I'm using the window.onunload event to trigger the unlocking of a
page, but I don't want the page to be unlocked when a postback or a
refresh occurs...I only want it when the user goes to another page or
closes the browser/tab...

Is it possible to achieve this behaviour??

Side note: I'm using ASP.NET 2.0 in the server side.

Regards,
Nuno

Aug 2 '07 #1
4 7891
"nrocha" <nu**********@gmail.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...
Hello,

I've been trying to detect when a user closes a page or navigates away
from it. This is part of a solution for locking pages (that is, if a
user enters a page, no one else can enter it while he doesn't leave).
I'm using the window.onunload event to trigger the unlocking of a
page, but I don't want the page to be unlocked when a postback or a
refresh occurs...I only want it when the user goes to another page or
closes the browser/tab...

Is it possible to achieve this behaviour??

Side note: I'm using ASP.NET 2.0 in the server side.

Regards,
Nuno
Now, I am not sure about how to do this in ASP, being a PHP man myself.
However, with a bit of AJAX behind it, you could make a function that
communicates with the server. If the page is currently being viewed, have
ASP open a file or database and mark the page as being read (say "1"). Once
you are done with the page, use the same function to change the file to read
something (say "0"). In JavaScript, all this would require is the standard
AJAX request, plus a function that submits the data, either 1 or 0, to the
server.

Hope that helps!
Matt

Aug 2 '07 #2
On Aug 2, 2:30 pm, "Matthew White" <mgw...@msn.comwrote:
"nrocha" <nuno.a.ro...@gmail.comwrote in message

news:11*********************@w3g2000hsg.googlegrou ps.com...
Hello,
I've been trying to detect when a user closes a page or navigates away
from it. This is part of a solution for locking pages (that is, if a
user enters a page, no one else can enter it while he doesn't leave).
I'm using the window.onunload event to trigger the unlocking of a
page, but I don't want the page to be unlocked when a postback or a
refresh occurs...I only want it when the user goes to another page or
closes the browser/tab...
Is it possible to achieve this behaviour??
Side note: I'm using ASP.NET 2.0 in the server side.
Regards,
Nuno

Now, I am not sure about how to do this in ASP, being a PHP man myself.
However, with a bit of AJAX behind it, you could make a function that
communicates with the server. If the page is currently being viewed, have
ASP open a file or database and mark the page as being read (say "1"). Once
you are done with the page, use the same function to change the file to read
something (say "0"). In JavaScript, all this would require is the standard
AJAX request, plus a function that submits the data, either 1 or 0, to the
server.

Hope that helps!
Matt
Hi,
all that you say it's true and it's what I'm doing right now. The big
problem is:
Once
you are done with the page, use the same function to change the file to read
something (say "0").
How can I detect this correctly? As I've said, I'm using the
window.onunload event but I don't want to unlock the page if I
continue in it (postback or refresh).
An alternative would be to add code to unlock the page when loading
every one of the other pages, but this way I would have to use
timeouts to force the page to unlock when the browser was closed or
when the user navigated away from my site to another...

I can't find a solution without any drawbacks...

Any sugestions??

Nuno

Aug 2 '07 #3
Matthew White said the following on 8/2/2007 9:30 AM:
"nrocha" <nu**********@gmail.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...
>Hello,

I've been trying to detect when a user closes a page or navigates away
from it. This is part of a solution for locking pages (that is, if a
user enters a page, no one else can enter it while he doesn't leave).
I'm using the window.onunload event to trigger the unlocking of a
page, but I don't want the page to be unlocked when a postback or a
refresh occurs...I only want it when the user goes to another page or
closes the browser/tab...

Is it possible to achieve this behaviour??

Side note: I'm using ASP.NET 2.0 in the server side.

Regards,
Nuno

Now, I am not sure about how to do this in ASP, being a PHP man myself.
However, with a bit of AJAX behind it, you could make a function that
communicates with the server. If the page is currently being viewed,
have ASP open a file or database and mark the page as being read (say
"1"). Once you are done with the page, use the same function to change
the file to read something (say "0"). In JavaScript, all this would
require is the standard AJAX request, plus a function that submits the
data, either 1 or 0, to the server.
That does nothing for telling you when/if/why the user left. Not even
window.onunload is reliable for that. The best you can do is a Server
Session with a timeout on it. In any event, to be reliable it *has* to
be handled on the server and that would mean posting to an ASP.NET group.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 2 '07 #4
"nrocha" <nu**********@gmail.comwrote in message
news:11*********************@k79g2000hse.googlegro ups.com...
On Aug 2, 2:30 pm, "Matthew White" <mgw...@msn.comwrote:
>"nrocha" <nuno.a.ro...@gmail.comwrote in message

news:11*********************@w3g2000hsg.googlegro ups.com...
Hello,
I've been trying to detect when a user closes a page or navigates away
from it. This is part of a solution for locking pages (that is, if a
user enters a page, no one else can enter it while he doesn't leave).
I'm using the window.onunload event to trigger the unlocking of a
page, but I don't want the page to be unlocked when a postback or a
refresh occurs...I only want it when the user goes to another page or
closes the browser/tab...
Is it possible to achieve this behaviour??
Side note: I'm using ASP.NET 2.0 in the server side.
Regards,
Nuno

Now, I am not sure about how to do this in ASP, being a PHP man myself.
However, with a bit of AJAX behind it, you could make a function that
communicates with the server. If the page is currently being viewed,
have
ASP open a file or database and mark the page as being read (say "1").
Once
you are done with the page, use the same function to change the file to
read
something (say "0"). In JavaScript, all this would require is the
standard
AJAX request, plus a function that submits the data, either 1 or 0, to
the
server.

Hope that helps!
Matt

Hi,
all that you say it's true and it's what I'm doing right now. The big
problem is:
>Once
you are done with the page, use the same function to change the file to
read
something (say "0").
How can I detect this correctly? As I've said, I'm using the
window.onunload event but I don't want to unlock the page if I
continue in it (postback or refresh).
An alternative would be to add code to unlock the page when loading
every one of the other pages, but this way I would have to use
timeouts to force the page to unlock when the browser was closed or
when the user navigated away from my site to another...

I can't find a solution without any drawbacks...

Any sugestions??

Nuno
Sorry, you are right. Instead, try logging the IP. If this IP isn't that
IP, then don't display the page. Once the onunload is triggered, set the
log to denote that the user left the page. Run a cron-job every 30 seconds
that checks the database and the timestamp. If the last person left, say, a
minute ago, release the IP and unlock the page.

Matt

Aug 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: giurax | last post by:
Hi all, I am new to javascript. I have a window that on the 'onUnload' event opens a new window, the question is: have I any chance to know in the new window what page is the opener loading? (in...
1
by: amith | last post by:
Hi, I have a javascript, calendar.js which i use to enable my client to select the date. This calendar pops up on the click of a gif image. But the problem is that this poped up window is not...
1
by: Geoff | last post by:
I have a javascript function that runs when onunload is triggerd. So this runs when someone navigates away from the page or closes the window. I only want the code to run when the window is closed....
8
by: Luke Matuszewski | last post by:
I have read all posts about how to detect that url have changed to new page and trigger the event handler then eg. function aidLogout(evt) { if(evt) { /* maybe via analyse of evt object i can...
7
by: hiriumi | last post by:
Hello folks, I have a web application that has basic authentication turned on (IIS). What I would like to accomplish is detect whether user is navigating away from the site or simply going to the...
4
by: Dst | last post by:
This is what i'm trying to do: I'm porting a windows app to a web app. I have a webform which will edit some data stored in a database. The data needs to be locked in the database, while editing....
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
37
by: Jan Tovgaard | last post by:
Hey everyone:) We have a critical problem, which I can see that other people also has ran into. In Internet Explorer 7 it is no longer possible to do a window.close after opening a window,...
4
by: goscottie | last post by:
I used submodal as my popup window. With some tweaks, it working great in my app. However, I can't find a way to detect session timeout in the popup window. The app is a form based...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.