473,218 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,218 software developers and data experts.

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 7880
"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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.