Such a task: I need to redirect to another page with the current one, but when updating the refresh button in the browser. I know how to make this code (so that CTRL + F5 on the F5 keys). And how to make it so that by clicking the mouse at the top in the browser to the reload icon, a redirect to another page is performed and not just an update
Asked
Active
Viewed 359 times
0
-
Are you looking for a redirection after a form has been submitted? Otherwise, I would look at the HTTP referer – Florent Roques May 04 '20 at 22:52
-
Does this answer your question? [How to redirect a page to another page when refresh at second attempt](https://stackoverflow.com/questions/8622892/how-to-redirect-a-page-to-another-page-when-refresh-at-second-attempt) – Johannes H. May 04 '20 at 22:53
-
Clicking the mouse outside of the web page content window — such as menus or bookmarks or the refresh button — can not be seen by the web page, so you can't intercept it. You would have to write a browser _plugin_ and then convince people to install that plugin. Clicking _refresh_ tells the browse to refresh the _current page_; it will load that page from cache and/or do a `GET` to the webserver of the _current page_, re-requesting it. (depends on which browser and modifier keys) – Stephen P May 04 '20 at 23:00
-
@StephenP WHile it is true that you cannot detect clicks outside the page itself with JS, you CAN detect the effect of such clicks on your website, as events such as `onbeforeunload` are triggered. SO you can certainly react to such events (there are also ways to tell apart which one triggered an event, such as the [Navigation Timing API](https://developer.mozilla.org/en-US/docs/Web/API/Navigation_timing_API). (Specifically [`PerformanceNavigationTiming.type`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming/type) – Johannes H. May 04 '20 at 23:46
-
@JohannesH. Yes, so you have to take advantage of _those_ things, possibly trying to figure out if the human is reloading (which the OP specifically asks about) vs leaving for another page (maybe I simply typed a new URL in the browser's location). I looked at the other question you linked as a possible duplicate and felt unsure if that is what the OP intends, otherwise I'd vote with you to close as a duplicate. – Stephen P May 05 '20 at 00:02
-
Not saying it's pretty, just saying it's possible. Not that you can actually intercept the unload event without the human's confirmation though. – Johannes H. May 05 '20 at 00:07