gpt4 book ai didi

javascript - firefox 浏览器拒绝全屏更改

转载 作者:数据小太阳 更新时间:2023-10-29 05:10:16 26 4
gpt4 key购买 nike

当我们点击它时,我试图让我的网站的一个元素全屏显示,它适用于 chrome、IE,但不适用于 firefox。

我去了microsoft fullscreen API ,我测试了他们的代码,这些浏览器都没有问题。

这里是我要全屏显示的网站部分。

<div class="wrap">
<div class="signin">
<div style="margin: 2px 0px -25px 10px;"><h1>Sign In or <a href="<?php echo $this->url(array('module' => 'default','controller'=>'paid-sign-up','action'=>'index'),null,true); ?>" style="color:#F00;text-decoration:none;">Signup</a></h1></div>
<?php echo $this->signin(); ?>
<span class="forget">
<a href="<?php echo $this->url(array('module' => 'default','controller'=>'forgot-password','action'=>'index'),null,true); ?>">Forgotten Password?</a> </span>
</div>

这里是我使用的脚本

    <script type="text/javascript">
var inFullScreen = false; // flag to show when full screen

var fsClass = document.getElementsByClassName("wrap");
for (var i = 0; i < fsClass.length; i++) {
fsClass[i].addEventListener("click", function (evt) {
if (inFullScreen == false) {
makeFullScreen(evt.target); // open to full screen
} else {
reset();
}
}, false);
}


function makeFullScreen(divObj) {
alert (divObj);
if (divObj.requestFullscreen) {
alert ('standard');
divObj.requestFullscreen();
}
else if (divObj.msRequestFullscreen) {
alert ('ms');
divObj.msRequestFullscreen();
}
else if (divObj.mozRequestFullScreen) {
alert ('moz');
divObj.mozRequestFullScreen();
}
else if (divObj.webkitRequestFullscreen) {
alert ('webkit');
divObj.webkitRequestFullscreen();
}
inFullScreen = true;
return;
}

function reset() {
if (document.exitFullscreen) {
document.exitFullscreen();
}
else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
}
else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
inFullScreen = false;
return;
}


</script>

最后一个有用的信息,我的网站是一个 zent 框架网站,这就是为什么有一些 PHP。

最佳答案

此代码段应该适用于大多数浏览器,包括。火狐浏览器。具体来说,Mozilla Firefox 坚持要求事件处理程序中的代码在 1 秒内执行。否则全屏请求被拒绝。引用:Bug Report

HTML

<button id="view-fullscreen">Fullscreen</button>

Javascript

var viewFullScreen = document.getElementById("view-fullscreen");
if (viewFullScreen) {
viewFullScreen.addEventListener("click", function() {
var docElm = document.documentElement;
if (docElm.requestFullscreen) {
docElm.requestFullscreen();
} else if (docElm.msRequestFullscreen) {
docElm.msRequestFullscreen();
} else if (docElm.mozRequestFullScreen) {
docElm.mozRequestFullScreen();
} else if (docElm.webkitRequestFullScreen) {
docElm.webkitRequestFullScreen();
}
})
}

更多细节请引用全屏API Fullscreen API

以上代码段的工作演示:Fullscreen Demo

关于javascript - firefox 浏览器拒绝全屏更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23913111/

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