473,320 Members | 2,109 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,320 software developers and data experts.

Capturing event user leaving page

Hi!

Is it possible to capture an event when user leaves the page and
execute some code? Not when he closes the window.

Any ideas?
Sep 2 '05 #1
8 4128
"Zvonko" <zv****@velepromet.hr> wrote in message
news:df**********@ss405.t-com.hr...
Hi!

Is it possible to capture an event when user leaves the page and execute
some code? Not when he closes the window.

Any ideas?


<head>
<script type="text/Javascript">
function yourFunction() {
alert("About to leave...");
}
</script>

<body onunload="yourFunction();">
...
</body>

--
Dag.
Sep 2 '05 #2
Dag Sunde said the following on 9/2/2005 9:53 AM:
"Zvonko" <zv****@velepromet.hr> wrote in message
news:df**********@ss405.t-com.hr...
Hi!

Is it possible to capture an event when user leaves the page and execute
some code? Not when he closes the window.

Any ideas?

<head>
<script type="text/Javascript">
function yourFunction() {
alert("About to leave...");
}
</script>

<body onunload="yourFunction();">
...
</body>


Are you positive that the alert will get fired when the page is left?

Power goes off, no alert......

Besides, I left. Why do you want to annoy me further with alerts, I
left, leave me be in peace.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 2 '05 #3
"Randy Webb" <Hi************@aol.com> wrote in message
news:gI********************@comcast.com...
Dag Sunde said the following on 9/2/2005 9:53 AM:
"Zvonko" <zv****@velepromet.hr> wrote in message
news:df**********@ss405.t-com.hr...
Hi!

Is it possible to capture an event when user leaves the page and execute
some code? Not when he closes the window.

Any ideas?

<head>
<script type="text/Javascript">
function yourFunction() {
alert("About to leave...");
}
</script>

<body onunload="yourFunction();">
...
</body>


Are you positive that the alert will get fired when the page is left?

Power goes off, no alert......

LOL

Of course I'm not sure. But the OP didn't specify nuclear strikes or
power outages. (And I *do* have an UPS). :D
Besides, I left. Why do you want to annoy me further with alerts, I left,
leave me be in peace.


Couldn't agree more.

But Now I have informed him how to do it (Not taking power failures
into account), and you have told him why he shouldnt. All we can do
now is to hope he use the knowledge and advice wisely.

--
Dag.
Sep 2 '05 #4
I would add that onUnload is fired when, really, the user has already
left (The request for a new page has already been sent to the server).
IE has onBeforeUnload which will actually catch the user before they
have issued the request although I doubt this is available for Firefox
or much else.

--------- beegee

Sep 3 '05 #5
bg*****@gmail.com wrote :
I would add that onUnload is fired when, really, the user has already
left (The request for a new page has already been sent to the server).
IE has onBeforeUnload
and Mozilla 1.7, Seamonkey 1.x and Firefox 1.x all have onbeforeunload
too since March 2004.

which will actually catch the user before they have issued the request although I doubt this is available for Firefox
or much else.


Gérard
--
remove blah to email me
Sep 4 '05 #6
Randy Webb wrote:

Are you positive that the alert will get fired when the page is left?

Power goes off, no alert......

Besides, I left. Why do you want to annoy me further with alerts, I
left, leave me be in peace.


Hi Randy.

I don't want to bother bother my visitors. The idea is that when the
user leaves the page to automatically log him off. I want that if the
user hit the Back button on the browser his session is timeouted and he
must login to access the page. Is this possible?
And if you have a web with multiple pages, how to implement the idea
with onunload? It would trigger the logoff even if the user is going to
another page inside the web site, and I don't want that. I would like to
log him off only when he is leaving the site.

Thanks for the answer.

Bye

Sep 5 '05 #7
Zvonko said the following on 9/5/2005 2:14 AM:
Randy Webb wrote:

Are you positive that the alert will get fired when the page is left?

Power goes off, no alert......

Besides, I left. Why do you want to annoy me further with alerts, I
left, leave me be in peace.

Hi Randy.

I don't want to bother bother my visitors. The idea is that when the
user leaves the page to automatically log him off. I want that if the
user hit the Back button on the browser his session is timeouted and he
must login to access the page. Is this possible?
And if you have a web with multiple pages, how to implement the idea
with onunload? It would trigger the logoff even if the user is going to
another page inside the web site, and I don't want that. I would like to
log him off only when he is leaving the site.

Thanks for the answer.


You use server-side sessions and timeouts.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 5 '05 #8
Zvonko wrote:
I don't want to bother bother my visitors. The idea is that when the
user leaves the page to automatically log him off. I want that if the
user hit the Back button on the browser his session is timeouted and he
must login to access the page. Is this possible?
And if you have a web with multiple pages, how to implement the idea
with onunload? It would trigger the logoff even if the user is going to
another page inside the web site, and I don't want that. I would like to
log him off only when he is leaving the site.

Thanks for the answer.


We have this problem too.

Our web server talks to a back end server that is written in a legacy
3GL with a contrived remote call facility which is licensed per session.
It's a monothread language, and the whole setup uses convoluted gobbets
of global data shared between *hundreds* of functions (it's *years*
old), so one web session consumes one back end server session for its
duration.

It's imperative that whenever a user closes their browser or navigates
away that the back end server session is closed down.

They have implemented the front page of the application as a frameset
(shudder!) with one frame in it - the application's login page. The
frameset has an onunload() method which pops up a window using
window.open("logout.jsp"). The logout.jsp closes the back end session
and sends a "window.close()" script to close the popped-up window. All
navigations within the app take place *within* the frame, so the
onunload is not triggered until the browser is closed or a new URL is
entered into the navigation bar.

I know, I know - it's ugly and unreliable (sudden power outages), but
it's what was there when I arrived, I've just tidied it up and made it a
little more reliable than it was.

I have thought of changing the method and implementing some kind of
"heartbeat" using window.setInterval() in every page's "onload" method
(we have a custom tag library which is used to create the page layout
which could do this), and XMLHttpRequest which sends an "I'm still here"
request every 10 seconds or so. The session would then have a
java.util.TimerTask scheduled to close the session down which would be
cancelled and re-scheduled upon receipt of that request.

Either way, it's not *really* supported, and it's going to be a hack.

Good luck, and post back your implemented solution.

Nige

Sep 10 '05 #9

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

Similar topics

1
by: Rich | last post by:
Hello, I want to create a cookie that will expire in a few mintues after a user leaves my page so that they can return without having to login again if they were only gone for a few minutes. I...
15
by: Tony Gahlinger | last post by:
I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007 Firebird/0.7) to do some client-side image processing. I want to capture the sequence of coordinates a user clicks on in xxx.jpg in the...
19
by: Heidi Hundåla | last post by:
Hi ! I have a Wep App in C#. Page_Unload fires after Page_Load, and it seems totally unreasonable when you want to use this event when you _leave_ the page. In my project we wanted to use...
6
by: Mike | last post by:
I have a web form in my application that will be used for both viewing and updating information. I have a requirement that if any data has been changed on the page and the user attempts to leave...
1
by: Jonah Olsson | last post by:
Hello, I'm trying to build an "add-on" to an already existing custom web user control. The old control collects some user data and saves it to a database. The new control should collect some...
10
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My...
1
by: louise raisbeck | last post by:
Hi there, i need to ensure a user does something when they exit an asp.net web page. I cant put code behind close buttons, because there are a thousand ways they can exit this page, menu...
5
by: sachu | last post by:
Hi Everyone, I want develop the intranet site with seamless authentication. Is there any way to capture only the user name who has logged in the windows machine. Iam using PHP 5.0 MySQL and IIS...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.