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

Is there a way to differ between refresh (F5) and leaving in onUnload?

Both refreshing (by pressing F5 or otherwise) a page, and
navigating away from a page leads to onUnload() triggering.

Is it possible to determine if the user is leaving the page
for another, or simply pressed refresh?

--
Dag.
Jul 23 '05 #1
3 2176
On Thu, 17 Mar 2005 11:04:40 GMT, in comp.lang.javascript "Dag Sunde"
<me@dagsunde.com> wrote:
| Both refreshing (by pressing F5 or otherwise) a page, and
| navigating away from a page leads to onUnload() triggering.
|
| Is it possible to determine if the user is leaving the page
| for another, or simply pressed refresh?


If the user clicks on a link on *your* page then you can capture it.
If the user types an address in the url line or select a site from
Favourites then your out of luck.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #2
It isn't simple.

You can capture the F5 key stroke with onkeydown() and set a global
boolean bRefresh = true, so the onload event would "know" that F5 was
used...
But if the user clicks the "Refresh" button, I can't find any way of
telling that.

--
Arik Segal
Tel-Aviv

On Thu, 17 Mar 2005 11:04:40 GMT, "Dag Sunde" <me@dagsunde.com> wrote:
Both refreshing (by pressing F5 or otherwise) a page, and
navigating away from a page leads to onUnload() triggering.

Is it possible to determine if the user is leaving the page
for another, or simply pressed refresh?


Jul 23 '05 #3
"Arik Segal" <ar**********@hotmail.com> skrev i meddelandet
news:fi********************************@4ax.com...
It isn't simple.

You can capture the F5 key stroke with onkeydown() and set a global
boolean bRefresh = true, so the onload event would "know" that F5 was
used...
But if the user clicks the "Refresh" button, I can't find any way of
telling that.

--
Arik Segal
Tel-Aviv

On Thu, 17 Mar 2005 11:04:40 GMT, "Dag Sunde" <me@dagsunde.com> wrote:
Both refreshing (by pressing F5 or otherwise) a page, and
navigating away from a page leads to onUnload() triggering.

Is it possible to determine if the user is leaving the page
for another, or simply pressed refresh?


F5 might be a shortcut to an arbitrary command (or none) on non-Windows
systems. The "Refresh" shortcut key combination might even be
user-configurable. So if you want to do this reliably, cross-platform and
cross-browser, I'd say you're out of luck.

--
Joakim Braun
Jul 23 '05 #4

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

Similar topics

2
by: Tipu Sattar | last post by:
Does anyone know how the refresh is trapped at www.nwolb.com. It seems to trap the refresh, using F5 key as well as the reload button, and gives the user a pop to allow them to continue or cancel...
1
by: Matt | last post by:
When we refresh the page (F5, or icon in browser), it will first trigger ONUNLOAD event and then trigger ONLOAD event. When we close the browser (X on right top icon), it will trigger ONUNLOAD...
3
by: Dag Sunde | last post by:
Is there a way to detect if the reason an onUnload() handler was called originated from the user explicitly refreshed the page(s)? Ie. pressed "Ctrl-R", "F5" or klicked the refresh button in...
8
by: Zvonko | last post by:
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?
8
by: Henrik Dahl | last post by:
Hello! I would like to introduce a keyboard shortcut for refreshing the user interface in many programs. In english locales it's often F5 which is used, but how about other locales and/or...
17
by: Jim Little | last post by:
Hello, I'm driving myself crazy either because I'm missing something about ASP.NET, or what I'm trying to do simply can't be done. First, I am not using session variables to track state. My...
2
by: Robert Mileski | last post by:
I've made some program in Visual Basic 2005 that works with changing files and folders. After I've finished it, the main problem is to refresh the Windows OS. I mean the same thing as when we press...
1
by: killygolaman | last post by:
Hi Guys, Have been looking at this for a while and not sure if there is a solution but hopefully someone can point me in the right direction: The problem is essential I want to undo an update...
0
acoder
by: acoder | last post by:
Problem onload and onunload events do not fire when going back, forward or refreshing the page Browser Opera Example Any code using onload or onunload, e.g. window.onload = init; where...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.