gpt4 book ai didi

javascript - 如何绑定(bind) "Exit Full Screen f11"浏览器按钮?

转载 作者:行者123 更新时间:2023-11-29 22:09:14 25 4
gpt4 key购买 nike

我用这段代码创建了一个全屏链接,来自 onclick go full screen

function toggleFullScreen() {
if ((document.fullScreenElement && document.fullScreenElement !== null) ||
(!document.mozFullScreen && !document.webkitIsFullScreen)) {
if (document.documentElement.requestFullScreen) {
document.documentElement.requestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) {
document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
}

现在,当浏览器处于全屏模式时,我如何绑定(bind)在窗口顶部弹出的浏览器“退出全屏 f11” 按钮做一些回调 在窗口通过退出全屏进入正常模式后?

最佳答案

试试这个-

var fullScreen = 0;
$( window ).keydown(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 122) {
if(fullScreen == 1) {
....
//your code goes here
....
}
fullScreen = (fullScreen == 1) ? 0 : 1;
}
});

我认为这应该适用于大多数浏览器

关于javascript - 如何绑定(bind) "Exit Full Screen f11"浏览器按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18982017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com