Flex disable keyboard shortcuts for Safari

I have a Flex application running on a web page and I want to use the Command+ key combination ←to trigger certain actions in the application. This is normal for most browsers, but in Safari, the browser captures this keyboard event and instead raises the browser back event. Is there a way, either through Flex or through JavaScript elsewhere on the page, that I can tell Safari not to do this?

+4
source share
1 answer

The short answer is, this is a (small) known bug for non-mac versions of safari. You cannot securely lock all keyboard shortcuts. Perhaps if you were more specific about what other shortcuts are you trying to block? Perhaps some of them will work. for example, cut copies have their own special locking methods. (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 are not the first to get here with this error.

+3
source

All Articles