1

所有键都可用于进入全屏,但似乎不是 ESC 键(它进入全屏但之后立即退出,似乎 preventDefault 没有帮助)б有什么想法吗?

function onkeydownP(b) 
{
    switch (b.keyCode) 
    {
    case 27: // KeyEvent.DOM_VK_ESC
        var el = document.documentElement
        var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen;
        rfs.call(el);
        b.preventDefault();
        break;
    }
}
window.addEventListener("keydown", onkeydownP, true);

编辑:将代码中的键码固定到右侧

4

1 回答 1

1

将事件键更改为 27 (ESC)。一个有用的资源http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

此外,您在el声明的末尾缺少一个分号。将您的代码更改为:

function onkeydownP(b) 
{
    switch (b.keyCode) 
    {
    case KeyEvent.DOM_VK_DOWN:
        var el = document.documentElement;
        var rfs = (el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen);
        rfs.call(el);
        cancelEvent(b);
        break;
    case 27: // KeyEvent.DOM_VK_ESC
        var el = document.documentElement;
        var rfs = (el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen);
        rfs.call(el);
        b.preventDefault();
        cancelEvent(b);
        break;
    }
}
于 2013-10-19T13:30:16.797 回答