开发者

How can I disable Alt-Enter in IE?

As the default behavi开发者_运维百科or of IE is to switch to the full screen mode on Alt-Enter command. I've to avoid this and have to attach a custom behavior.

Is it doable?


Not in JavaScript, no.

This is a behaviour of the application, which you don't really have control over (aside from browser extensions, and such).

You could try catching the key presses on your page, but it wouldn't prevent the user from easily circumventing it.

See http://www.webonweboff.com/tips/js/event_key_codes.aspx for a list of the character codes for keys. I'm pretty sure it's not reliable for catching combinations of key presses.

Besides, Alt+Enter in IE results in an expected behaviour and you should not try to override this via a webpage.


Since you can't beat 'em, join 'em. Meaning, since you can catch the event but can't stop it, how about you just run the same command in a timeout after the user presses alt+enter?

Example:

<script type="text/javascript">

document.onkeydown = handleHotKeys;

function handleHotKeys(e) {
    var keynum = getKeyCode(e);
    var e = e || window.event;
    if (keynum==13 && e.altKey) { // handle enter+alt
        setTimeout("toggleFullscreenMode",100);
    }

}
function getKeyCode(e){
    if (!e)  { // IE
        e=window.event;
        return e.keyCode;
    } else { // Netscape/Firefox/Opera
        return e.which;
    }
}

function toggleFullscreenMode() {
  var obj = new ActiveXObject("Wscript.shell");
  obj.SendKeys("{F11}");
}
</script>

DISCLAIMER: Tested in IE8. You will have to look at the browser and version to get this to work for the specific version of the browser you are targeting. This also assumes that the user will have javascript and activex objects enabled.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜