473,765 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4159
"Zvonko" <zv****@velepro met.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="yourF unction();">
...
</body>

--
Dag.
Sep 2 '05 #2
Dag Sunde said the following on 9/2/2005 9:53 AM:
"Zvonko" <zv****@velepro met.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="yourF unction();">
...
</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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 2 '05 #3
"Randy Webb" <Hi************ @aol.com> wrote in message
news:gI******** ************@co mcast.com...
Dag Sunde said the following on 9/2/2005 9:53 AM:
"Zvonko" <zv****@velepro met.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="yourF unction();">
...
</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.c om 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.javas cript 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("lo gout.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.setInter val() 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.Timer Task 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
1880
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 tried putting this code in the Page_Unload event but got an error message that cookies not supported here. .... Sub Page_Unload 'this not working here
15
7052
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 following html <a href="#"><IMG SRC="xxx.jpg" ISMAP></a> and save these to a file for later handling. The coordinates appear on the bottom left of the window as I move the mouse, so I know they're being passed around somehow, but I haven't...
19
3492
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 the Page_Unload - event to clean up the Session variables, but when it turns out that it fires before the end, it screws up the code, and
6
18434
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 the page without saving, the user gets prompted with a message asking if they want to save changes. It seemed logical to put any code to handle this in the page unload event, however the page unload event gets fired every time the page does a post...
1
1436
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 extra info from the user and add it to a new table in the database. The old control should not be re-written (at least not now..), so I need a way of capturing the click event of the Save button in the old control. This event should trigger a...
10
6020
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 code is in C#/ASP.NET. TIA. Andrew.
1
1420
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 buttons, links etc. Is there any way you can capture the exiting of a page/the moment the server receives a request to move away from a particular url ? Page_Unload, although it sounds ideal, actually doesnt capture the unload of a page, but the moment...
5
10223
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 Server. I have tried with $_SERVER but its returning nothing. Please help me out.
1
108772
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 button anyways, if the user ventures away from your page then they wouldn't have this button at their disposal. The main reason people ask how to control or disable the back button is because they have a need to control sensitive (and/or) dynamic web...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8832
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
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 we have to send another system

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.