Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 715
Dennis Martinez Avatar asked Oct 25 '25 17:10

Dennis Martinez


1 Answers

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.

like image 74
Will Mulligan Avatar answered Oct 28 '25 06:10

Will Mulligan