I have a Flex app running on a web page, and I want to use the Command+← key combination to trigger certain actions in the app. This is fine on most browsers, but on Safari, the browser intercepts this keyboard event and causes the browser "back" event instead. Is there a way, either through Flex or via JavaScript elsewhere on the page, that I can tell Safari not to do that?
Asked
Active
Viewed 976 times
5
-
3It is generally bad form to intercept keyboard events and make them do something they're not meant to, and is actually one of the reasons public opinion of Flash dropped so quickly. I would have to advise against doing this and finding another combo to use. – Josh Oct 24 '13 at 23:23
-
1Even if it's a bad idea, I still want to know how it can be done. – Dan Burton Oct 29 '13 at 18:24
-
You won't be able to do it via AS3, for sure. It would have to be done through Javascript. See http://stackoverflow.com/questions/7295508/javascript-capture-browser-shortcuts-ctrlt-n-w – Josh Oct 29 '13 at 18:34
-
I believe it is doable, even in the post Josh mentioned, JS/AS or with interactions between the two. but I think Burton is right, it's not what they meant to – zinking Nov 05 '13 at 09:54
-
Are you're having this problem on non-mac versions of safari only? – Still.Tony Nov 05 '13 at 13:49
1 Answers
3
Short answer, it's a (little) known bug on non-mac versions of safari. You can't reliably block all shortcut keys. Perhaps if you were more specific about what other shortcuts you're trying to block? Maybe some of them will work. e.g. cut paste copy have their own special methods of blocking. (Although it seems like you probably already know that.)
Are you using something like this?
function blockKeys(e) {
var blocked = new Array('c','x','v');
var keyCode = (e.keyCode) ? e.keyCode : e.which;
var isCtrl;
if(window.event)
isCtrl = e.ctrlKey
else
isCtrl = (window.Event) ? ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;
if(isCtrl) {
for(i = 0; i < blocked.length; i++) {
if(blocked[i] == String.fromCharCode(keyCode).toLowerCase()) {
return false;
}
}
}
return true;
}

Community
- 1
- 1

Still.Tony
- 1,437
- 12
- 35