Javascript: onrefresh or onreload?

I need an event handler that fires when a user clicks on a reboot. Is onrefresh or onreload the right handler to add? Also, is it even a fire before or after onunload? Are there browser inconsistencies? Thanks.

+5
source share
6 answers

I do not think there are events called onrefresh or onreload. You can know when the page is being loaded, but knowing why (that is, where the user goes next) is outside the JavaScript security sandbox. The only way to find out if the page was reloaded is to know where the user was in the last page request, which also goes beyond JavaScript. Sometimes you can get this through document.referrer, but it uses browser security settings to allow access to this information.

+5
source

cookie a , onload, , . cookie , , .

+2

onreload onrefresh, . , javascript, , . . , onunload , , .

0

, , ... , , cookie, ; , , unload ed JavaScript (- , , , ?) ; , , , .:)

0

. , cookie, . , . , superglobal . , , .

0

WindowEventHandlers.onbeforeunload , beforeunload. , .

window.onbeforeunload = function () {
   return 'Are you sure you want to leave?';
}

, . .

Confirmation cannot be found because it can be used for malicious reasons.

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload

0
source

All Articles