/    Sign up×
Community /Pin to ProfileBookmark

Javascript function keys

Hi,

Does anybody has a cross browser script for detecting function keys.. am trying to print a web page when user clicks on F8 key .. for Internet Explorer am able to get window.event.keycode which is 119 …but how to let my code work on all browsers .. for the above function.. anybody pls.help.

thanks

i’ve a function which works in i.e., but not in NETSCAPE or FIREFOX. PLS.HELP..

the below function works in I.E

document.onkeydown = function(){

if(window.event && window.event.keyCode == 119)
{ // Capture and remap F5
window.event.keyCode = 505;
}

if(window.event && window.event.keyCode == 505)
{ // New action for F5
alert(‘F8 key was pressed’);
return false;
// Must return false or the browser will refresh anyway
}
}.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@pccodeOct 08.2005 — <i>
</i>document.onkeydown = function getcode(ev) {

value = (window.external) ? event.keyCode : ev.keyCode;

//tells you the code of the button which was pressed
//F5 = 116, F8 = 119
alert(value);

if (value == 116) { value = 119; }

if (window.external) {
if (event.keyCode == 119 || value == 119) { alert("You pressed F8"); }
} else {
if (ev.keyCode == 119 || value == 119) { alert("You pressed F8"); }
}
}


Sorry about the previous script. It should be working now.
×

Success!

Help @chavasreedhar 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.19,
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,
)...