faqts : Computers : Programming : Languages : JavaScript : Event handling

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

7 of 20 people (35%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I capture the funktion keys (F1,F2....F5) on Netscape!?

May 16th, 2006 23:23
kris kris, bogo,


capture the onkeypress event and add some functionality to get the
keycode of events fired by FunctionKeys(F1-F12)..
evt.charCode will return 0 in Firefox, so you need to use 
evt.keyCode, iam adding my sample code which disabling the F5 & CTRL+R
functionality in Firefox & Netscape.
the event codes start from (F1[112] to F12[123]}....
the numbers in Square brackets indicates the keycode of the function key.
if(browser == "Netscape")
{
	document.onkeypress = function (evt)
	{
		var r = '';
		if (document.getElementById)
		{
			r += evt.ctrlKey ? 'Ctrl-' : '';
			r += evt.charCode;
			if(evt.keyCode =="116" || r == "Ctrl-114") // event fired by NS when
F5(keycode:116) button is pressed.
			{
				 evt.preventDefault();
				 evt.stopPropagation();
				 return false;
			}
		}
	}
}
Hope this solves your problem..
thanks,
krishna