Randy Webb & Michael Winter,
I think you are too close minded...
To disable the F5 key doesn't necessarily mean that
the programmer can't solve a "refresh issue".
e.g.
I'm moving a "mainframe application" to a web application.
I don't want the users to change their way of working...
They are used to:
- press F1 to inqury
- press F2 to insert
- press F3 to update
- press F4 to delete
- press F5 to release
....
As you can see I need to intercept the function keys and to
change their functionality.
--------------------------------------------
Back to the topic...
This is what I've done:
/*
* Intercept all the 'function keys' and invokes the related submit input
* (if one exists). This method must be invoked when a "keydown" event occurs
*/
function interceptKeyDown(e) {
keyCode = e.keyCode;
if( keyCode >= asciiF1 && keyCode <= asciiF12 ||
keyCode >= asciiPgUp && keyCode <= asciiHome ) {
e.keyCode = 505;
clickButton( keyCode );
return false;
}
}
attachEventListener(document,"keydown",interceptKe yDown,true);
/*
* Intercept all the 'function keys' and invokes the related submit input
* (if one exists). This method must be invoked when a "keypress" event occurs
*/
function interceptKeyPress(e) {[indent]
if( !e ) {
if( window.event ) e = window.event;
else return;
}
//NS 4, NS 6+, Mozilla 0.9+, Opera
if( typeof( e.which ) == 'number' ) {
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : void 0;
if(e.charCode == null || e.charCode == 0 ){
if( keyCode >= asciiF1 && keyCode <= asciiF12 ||
keyCode >= asciiPgUp && keyCode <= asciiHome ) {
e.stopPropagation();
e.preventDefault();
clickButton( keyCode );
}
}
}
}
attachEventListener(document,"keypress",interceptK eyPress,true);
/*
* According to the type of browser, adds a new event listener to
* the specified object ,for the requested event, binded to the
* specific function.
*/
function attachEventListener( obj, type, func, capture ) {
if(window.addEventListener){ // Mozilla, Netscape, Firefox
obj.addEventListener( type, func, capture );
} else { // IE
obj.attachEvent( 'on' + type, func );
}
}
the function clickButton( keyCode ) changes according to your specifications