By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,627 Members | 1,781 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,627 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.