Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent the default page-refresh behavior of key F5 in IE and others

Status
Not open for further replies.

johnjsforum

Programmer
Jul 30, 2007
11
US
Buddies,
I want to prevent the default behavior of the F5 key for my web page in Internet Explorer and other browsers. Please give me some ideas to do that. By default, in the browsers, when users hit key F5 (on their keyboard), a web page will be reloaded or refreshed. I do not want such behavior happens when users hit F5.
Thanks in advance.
johnaspnet
 
Do you also want to stop users using the browser refresh features (e.g. refresh button, right-click and "refresh", etc), or just stop F5 from refreshnig so you can use it for some other purpose?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
You can't, anyway. The closest you will be able to get is the solution I recently posted in the FAQ section faq216-6708.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thanks for your posts.
I successfully make other reloading/refreshing-made factors on my window popup such as "hide reload/refresh button", "right mouse context menu click". The rest is I am looing for a solution that prevents "F5 default behavior" from its reloading/refreshing when users hit it.

The reason I'd like to do for my window popup menu is I'd like the "unload" event happens only one time WHEN users hit the top-right-corner X button on IE, FF, or others. I do not want that event happens when users hit F5.

By the way, I am not sure whether the "beforeunload" event is browser-cross one. It works for IE, FF, Opera, NetScape, etc? It works for new and old versions od such browser? The "beforeunload" event is mentioned in article " FAQ216-6708: How to prevent page reloading with a non-submitted form."


 
I wrote that article. It works in Safari, Firefox, IE6, IE7 that I know of (Mac and Windows). You can copy-paste the demo page and try it yourself on other browsers to test it. I would be interested in your results.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
I know that the knee jerk reaction is to try to prevent a user's browser from doing something you don't want. However, to truly program for the web, you need to think of how to preserve the integrity of your web site and data regardless of the user's actions.

Instead of preventing the "back button" or "F5", you should find a way to keep your site solid in all user conditions.

Einstein47
There are no kangaroos in Austria!
[[]Starbase47.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top