I came across a very interesting problem recently. Basicly I am building an editor and I want to take advantage of hot keys. I got it working perfectly in Internet Explorer, But I hit problems when I tried in Firefox, stranger still I found Chrome worked fine.
The problem is the use of hotkeys that are already used in firefox. In my example I have used Ctrl-S (Save page in both FF and Ch). Now I would think evt.preventDefa ult(); would be the answer, unfortunately this does not work in ff (does in chrome though?).
I have later found, It will work but only when its a <input> or other form control with the event handler. I think this is a bit sad, anyway around it?
Also note straight away I thought of google docs, soon found out the problem actually occurs in google doc's just the same.
Thanks. Josh
The problem is the use of hotkeys that are already used in firefox. In my example I have used Ctrl-S (Save page in both FF and Ch). Now I would think evt.preventDefa ult(); would be the answer, unfortunately this does not work in ff (does in chrome though?).
I have later found, It will work but only when its a <input> or other form control with the event handler. I think this is a bit sad, anyway around it?
Code:
var keydownfunc = function(e){
if(!e)e=window.event;
if(window.event){e.returnValue = false;e.cancelBubble = true;}
else {e.preventDefault();e.stopPropagation();}
if(e.ctrlKey && e.keyCode == 83)
alert('Save Doc now');
document.focus();
}
window.addEventListener?
document.addEventListener('keydown',keydownfunc,false)
:document.attachEvent('onkeydown',keydownfunc);
Thanks. Josh
Comment