• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to identify when refresh button of browser or f5 is pressed

 
kranthi chamarthi
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there a way to identify the browser refresh button click and f5 press using JavaScript. My requirement is like, i am having a page to which user comes after he submits some data and if in this page the user clicks refresh button or presse's f5 then the data will be sent again. To avoid this, i want to identify the refresh click or f5 press using JavaScript and want to change the url. The solution should work in ie, Mozilla as well as safari.
Thanks
Kranthi
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no event for the refresh button.

Eric
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Capture the ASCII code for the key pressed. For F5, it is 116. So, in your javascript event, capture the "onkeypress" event, and see if it is 116.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dawn, and what about Control-R, the button in the browser, right click, etc. There are too many things to catch that refresh the page.

Eric
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand, Eric.... but then the question was to differenciate between only two of those scenarios... and hence the reply
 
kranthi chamarthi
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need solution for "refresh" of the page by any means
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Unnecessary and not-so-nice response removed.]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dawn Charangat wrote:.. but then the question was to differenciate between only two of those scenarios... and hence the reply

As JavaRanch is a learning site, it's important to realize that there's more to an answer sometimes than just the answer to the specific question a poster might ask.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic