Is there a way to detect if the user has pressed the refresh button using jquery or javascript?

前端 未结 5 2086
[愿得一人]
[愿得一人] 2021-01-22 12:48

I want to know if jquery or javascript can detect if the user has pressed the refresh button of their browser? If so can I see an example?

5条回答
  •  耶瑟儿~
    2021-01-22 13:09

    There is no way to detect if the user pressed refresh before the page refreshes, but you can use cookies to determine if the page refreshed once it loads the second time.

    For example, each page could store the location.href in a cookie, and if the last cookie equals the same location.href of the current page, then the user most likely refreshed the page.

提交回复
热议问题