aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to identify when refresh button of browser or f5 is pressed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to identify when refresh button of browser or f5 is pressed" Watch "How to identify when refresh button of browser or f5 is pressed" New topic
Author

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

kranthi chamarthi
Ranch Hand

Joined: May 08, 2007
Posts: 95
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no event for the refresh button.

Eric
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Apr 26, 2007
Posts: 249
I understand, Eric.... but then the question was to differenciate between only two of those scenarios... and hence the reply
kranthi chamarthi
Ranch Hand

Joined: May 08, 2007
Posts: 95
I need solution for "refresh" of the page by any means
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
[Unnecessary and not-so-nice response removed.]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to identify when refresh button of browser or f5 is pressed