/    Sign up×
Community /Pin to ProfileBookmark

Suppress F5 key

Hi,

I have a webpage (asp) that needs to capture F5 event and ignore it. As you may understand this is necessary to avoid refreshing the page and also unnecessary send a stream back to the server.

I know document.captureEvents(Event.KEYPRESS) can be used to divert all keypress events to a user-defined function and then checking for F5 key. Is there a better or elegant way to handle this.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvJan 12.2004 — You simply can't cancel events like that. These events execute on a browser level, however, since they are explictily define shortcuts for the actual browser they simply can't be canceled. Sure, you can interrupt them (such as alerts, etc.), but you can't cancel them.
Copy linkTweet thisAlerts:
@KorJan 12.2004 — Here's the code to capture:

if (document.layers) { document.captureEvents(Event.KEYPRESS); }

document.onkeydown = getKey;

function getKey(keyStroke) {

var keyCode = (document.layers) ? keyStroke.which : event.keyCode;

var keyString = String.fromCharCode(keyCode).toLowerCase();

}

But hmmmmm... I don't think that you can suppress the F5 meaning even if u can capture the key stroke this way... As far as I know, there are some keys you can not modify or stop their meaning... (ENTER, F1, F5... and combination as Alt+F4, CTRL+C, CTRL+V....). You may fire another function using them but, till the end that specific key will do it's genuine job anyaway...
×

Success!

Help @lmrswamy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...