faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

169 of 208 people (81%) answered Yes
Recently 9 of 10 people (90%) answered Yes


Can I disable any of the function keys using JavaScript?
Yes this is fine as long as I have a document without frames. How can i implement it for all frames

Apr 4th, 2008 19:52
ha mo, Darton Williams, Bj Price, Colin Fraser, Vicky Hora, chitra prakash,

(As mentioned elsewhere on this site)
I found a way to do it, but it only works in IE and I've only tested it 
in IE5+. Netscape doesn't seem to return anything for function keys. If 
you trap the keyCode you want to disable and assign a new value to it, 
you can do whatever you want with the function keys. The keycodes for 
them are 112 - 123. The only real use I've found for this is in a 
proprietary app I'm developing for IE, but I guess you could also annoy 
the heck out of some people with it.
document.onkeydown = function(){
if(window.event && window.event.keyCode == 116) 
        { // Capture and remap F5
	window.event.keyCode = 505;
if(window.event && window.event.keyCode == 505) 
        { // New action for F5
	alert('F5 key was pressed');
	return false; 
        // Must return false or the browser will refresh anyway
This will not intercept F1 or F4 in IE 6.  Anybody have any guesses how 
F1 doesn't need to be remapped in the same way as the others, because 
document.onhelp will override the default function. Still checking on 
the F4 thing.