Hello,
I'm currently overriding function keys (F1 to F4) to perform other
actions. In order to do this the default popup windows of Help (F1),
Seach(F3) etc must be turned off. In FF it's easy enought to do using
the preventDefault and stopPropagation event functions.
IE's equivalent is supposed to be cancelBubble and returnValue,
however I can not seem to get them to stop no matter what I try.
Can someone please point out my error? The test code is below.
------
var classKeyPressOv erride = function(){}
classKeyPressOv erride.prototyp e.toString = function(){ return " Class
Key Press Override "; }
classKeyPressOv erride.prototyp e.attachListene r = function( type,
functionCode ){
//Register the listener
var obj = window.document ;
if ('addEventListe ner' in obj) {
obj.addEventLis tener( type, functionCode, true);
} else if ('attachEvent' in obj) {
obj.attachEvent ('on' + type, functionCode );
} else {
alert("Could not add listener");
}
}
//Create an instance and add attach a lister tpe of keydown
var classKP = new classKeyPressOv erride();
classKP.attachL istener('keydow n', function(event) {
var ev = event || window.event;
var keyCode = ev.keyCode || ev.which;
alert("aatrying " + keyCode);
var fKeyPressed = false;
//IE won't like the regular ev.DOM_VK_F1 so use keyCode values.
if (keyCode == 112) {
fKeyPressed = true;
alert("ev F1 Pressed");
}else if (keyCode == 113) {
fKeyPressed = true;
alert("F2 Pressed");
}else if (keyCode == 114) {
fKeyPressed = true;
alert("F3 Pressed");
}else if (keyCode == 115) {
fKeyPressed = true;
alert("F4 Pressed");
}
if (fKeyPressed){
//Prevent help menu and other default F1 key functions
if ('stopPropagati on' in ev) {
ev.stopPropagat ion();
ev.preventDefau lt();
}else{
// Trying to stop the popup windows in IE
//Does not seem to work...
ev.cancelBubble = true;
ev.returnValue = false;
}
}
}
);
I'm currently overriding function keys (F1 to F4) to perform other
actions. In order to do this the default popup windows of Help (F1),
Seach(F3) etc must be turned off. In FF it's easy enought to do using
the preventDefault and stopPropagation event functions.
IE's equivalent is supposed to be cancelBubble and returnValue,
however I can not seem to get them to stop no matter what I try.
Can someone please point out my error? The test code is below.
------
var classKeyPressOv erride = function(){}
classKeyPressOv erride.prototyp e.toString = function(){ return " Class
Key Press Override "; }
classKeyPressOv erride.prototyp e.attachListene r = function( type,
functionCode ){
//Register the listener
var obj = window.document ;
if ('addEventListe ner' in obj) {
obj.addEventLis tener( type, functionCode, true);
} else if ('attachEvent' in obj) {
obj.attachEvent ('on' + type, functionCode );
} else {
alert("Could not add listener");
}
}
//Create an instance and add attach a lister tpe of keydown
var classKP = new classKeyPressOv erride();
classKP.attachL istener('keydow n', function(event) {
var ev = event || window.event;
var keyCode = ev.keyCode || ev.which;
alert("aatrying " + keyCode);
var fKeyPressed = false;
//IE won't like the regular ev.DOM_VK_F1 so use keyCode values.
if (keyCode == 112) {
fKeyPressed = true;
alert("ev F1 Pressed");
}else if (keyCode == 113) {
fKeyPressed = true;
alert("F2 Pressed");
}else if (keyCode == 114) {
fKeyPressed = true;
alert("F3 Pressed");
}else if (keyCode == 115) {
fKeyPressed = true;
alert("F4 Pressed");
}
if (fKeyPressed){
//Prevent help menu and other default F1 key functions
if ('stopPropagati on' in ev) {
ev.stopPropagat ion();
ev.preventDefau lt();
}else{
// Trying to stop the popup windows in IE
//Does not seem to work...
ev.cancelBubble = true;
ev.returnValue = false;
}
}
}
);
Comment