Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
Ranch Hand
Posts: 98
  • 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
 
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
 
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: 98
  • 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.]
 
Author and ninkuma
Marshal
Posts: 66783
168
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
Boost this thread!