通过按钮将网站切换到持久全屏模式
Switching website into persistent full screen mode with a button
我正在努力在我的网站上实现两个目标:
1.切换到全屏模式的按钮
2.在页面之间传递时,将保持全屏模式。
我能够单独实现这两个目标,但不能一起实现
目前的情况是:
1.按钮使用以下代码切换到全屏模式:
<script>
function toggleFullScreen() {
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
}
</script>
<li class="quicklinks"> <a href="#" class="layout-condensed-fullwidth" id="layout-condensed-width" >
<div onclick="toggleFullScreen();" class="iconset top-menu-fullpage-dark"></div>
</a> </li>
但是,当切换页面时,全屏模式将退出!
当通过点击F11(而不是如上所述)切换到全屏模式时,我能够使用以下代码使全屏持久:
<script> function fullscreen(){ $('a').click(function() { if(!$(this).hasClass('noeffect')) { window.location = $(this).attr('href'); return false; } }); $(document).ready(function() { fullscreen(); }); </script>
但我找不到将这两者结合起来的方法。第2节中的代码只有在按F11时才有效。关于为什么会发生这种情况以及什么可以帮助解决这个问题,有什么想法吗?
谢谢!
根据MDN-使用全屏模式在全屏模式下导航到另一个页面、更改选项卡或切换到另一应用程序(例如使用Alt Tab)退出全屏模式。
然而,我在全屏API包装器中看到了一个技巧/破解来解决这个问题。它使用iframe可以在全屏状态下切换页面。也许你可以使用这个包装器或者从代码中寻找灵感。请参阅演示。
这里是代码片段:
// a little hack to be able to switch pages while in fullscreen.
// we basically just creates a seamless iframe and navigate in that instead.
$('#iframe').click(function () {
// We create an iframe and fill the window with it
var iframe = document.createElement('iframe')
iframe.setAttribute('id', 'external-iframe');
iframe.setAttribute('src', 'http://bbc.com');
iframe.setAttribute('frameborder', 'no');
iframe.style.position = 'absolute';
iframe.style.top = '0';
iframe.style.right = '0';
iframe.style.bottom = '0';
iframe.style.left = '0';
iframe.style.width = '100%';
iframe.style.height = '100%';
$('#container').prepend(iframe);
document.body.style.overflow = 'hidden';
})
也许您可以将iframe.src
更改为链接href
,而不是更改window.location
。
相关文章:
- 在编辑内联模式下禁用Kendo Ui网格按钮
- 如何根据在模式中单击的按钮发送参数
- 如何在同一页面上的多个按钮上打开一个引导模式
- 模式上的后退和前进按钮位于图像库上(可滚动浏览)
- 如何在不点击按钮的情况下打开引导模式
- 使用按钮关闭 iframe 模式
- CKEditor内部的jQuery模式问题与按钮
- 如何使用JQuery收听引导模式按钮的onClick事件
- 引导多个模式按钮
- 引导模式按钮没有响应
- 如何使用 jquery 将变量传递给引导确认模式按钮
- 显示动态插入的模式按钮
- 确认模式按钮 asp.net 的操作
- 通过a - frame的VR模式按钮隐藏页面元素
- 引导模式按钮不能自动对焦
- Angular-ui bootstrap模式按钮不会执行函数
- Rails:Foundation5显示提交模式按钮
- 用event.preventDefault引导模式按钮不触发
- 编辑模式按钮
- 引导模式按钮点击事件没有在第一次触发