Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex disable Safari keyboard shortcuts

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?

like image 417
Dan Burton Avatar asked Oct 21 '22 22:10

Dan Burton


1 Answers

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;
}

You're not the first to get hit with this bug on here

like image 138
Still.Tony Avatar answered Oct 27 '22 10:10

Still.Tony