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

前端 未结 5 2078
[愿得一人]
[愿得一人] 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 12:57

    I'm not sure you can do that, but what you could do instead as a hacky workaround is maybe render the referring page URL from the server into a hidden input or something, and on page load, check to see if the value of the hidden div is the same as the current URL. If it is, it must be a postback or a refresh.

提交回复
热议问题