在最近的浏览器中将整个窗口设置为全屏

编程入门 行业动态 更新时间:2024-10-26 22:19:40
本文介绍了在最近的浏览器中将整个窗口设置为全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想允许用户单击链接,以使用浏览器正在部署的RequestFullScreen函数将我的网页完全显示为全屏.您可以在此处页面查看.根据建议的此处,我正在调用document.documentElement的requestFullScreen方法.代码如下:

I wanted to allow users to click a link to make my webpage entirely full screen, using the RequestFullScreen function that browsers are deploying. You can see the page here. As suggested here, I'm calling requestFullScreen method of document.documentElement. The code looks like this:

var el = document.documentElement , rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen ; if(typeof rfs!="undefined" && rfs){ rfs.call(el); }

问题是,这样做的确很奇怪,在我的情况下,背景大部分是黑色的(您可以查看是否单击链接).难道我做错了什么?在我测试过的所有浏览器中,在浏览器中手动设置全屏功能都可以正常工作,这使我认为documentElement可能在某种程度上还不够全面.

The thing is, I get really strange artifacts doing this, in my case the background is mostly black (you can see if you click the link). Am I doing something wrong? Manually setting fullscreen in the browser works just fine in all the browsers I've tested, which made me think maybe documentElement is somehow not inclusive enough.

document.documentElement.mozRequestFullScreen似乎与用户手动设置全屏功能不同.有什么不同?为什么这种差异会引起问题?

it seems like document.documentElement.mozRequestFullScreen doesn't do the same thing as the user manually setting fullscreen. What's the difference? Why is this difference causing problems?

推荐答案

使用此功能完成此操作.

Got this done with this function.

// Launch full screen function launchFullscreen(element) { if(element.requestFullscreen) { element.requestFullscreen(); } else if(element.mozRequestFullScreen) { element.mozRequestFullScreen(); } else if(element.webkitRequestFullscreen) { element.webkitRequestFullscreen(); } else if(element.msRequestFullscreen) { element.msRequestFullscreen(); } }

全文

更多推荐

在最近的浏览器中将整个窗口设置为全屏

本文发布于:2023-10-08 09:00:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472138.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   全屏   中将   浏览器   窗口

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!