gpt4 book ai didi

Firefox 上的 Javascript mozfullscreenchange

转载 作者:行者123 更新时间:2023-12-02 19:23:15 29 4
gpt4 key购买 nike

我尝试通过 Javascript 中的 fullscreenchange 来了解用户何时全屏显示 div。该脚本适用于 Chrome(设置全屏 div,显示警报,然后当关闭全屏时,再次显示警报),但不适用于 Firefox。为什么?

<!DOCTYPE html>

<head>
<meta content="text/html; Charset=UTF-8" http-equiv="Content-Type" />
<title>test fullscreenchange </title>

</head>

<body>
<div id="macarte" class="csscarte" style="color: green" >my div</div>
<button onclick="goFullscreen('macarte'); return false">showfullscreen</button>

<script type="text/javascript">


function fullscreenouinon() {alert("Full Screen Change !");};

function goFullscreen(id) {


// Get the element that we want to take into fullscreen mode
var thediv = document.getElementById(id);

// These function will not exist in the browsers that don't support fullscreen mode yet,
// so we'll have to check to see if they're available before calling them.

if (thediv.requestFullScreen) {
//fonction officielle du w3c
thediv.addEventListener("fullscreenchange", function() {fullscreenouinon()}, false);
thediv.requestFullScreen();
} else if (thediv.webkitRequestFullScreen) {
//fonction pour Google Chrome (on lui passe un argument pour autoriser le plein écran lors d'une pression sur le clavier)
thediv.addEventListener("webkitfullscreenchange", function() {fullscreenouinon()}, false);
thediv.webkitRequestFullScreen(thediv.ALLOW_KEYBOARD_INPUT);
} else if (thediv.mozRequestFullScreen){
//fonction pour Firefox

thediv.addEventListener("mozfullscreenchange", function() {fullscreenouinon()}, false);

thediv.mozRequestFullScreen();
} else {
alert('Votre navigateur ne supporte pas le mode plein écran, il est temps de passer à un plus récent ;)');
}

};
</script>
</body></html>

最佳答案

“当成功进入全屏模式时,包含该文档的文档会收到一个 mozfullscreenchange 事件。当退出全屏模式时,该文档会再次收到一个 mozfullscreenchange 事件。请注意,mozfullscreenchange 事件不提供任何有关文档是否进入或退出全屏模式的信息本身,但如果文档具有非空 mozFullScreenElement,则您知道自己处于全屏模式。”取自这里 - https://developer.mozilla.org/en-US/docs/DOM/Using_full-screen_mode

因此,您应该将 mozfullscreenchange 事件的EventListener 添加到 document,而不是添加到元素(并检查非 null mozFullScreenElement?)。

关于Firefox 上的 Javascript mozfullscreenchange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12284198/

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