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

D

Dag Sunde

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?
 
J

Jeff North

| 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.
 
A

Arik Segal

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.
 
J

Joakim Braun

Arik Segal said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top