因此,我正在制作一款游戏,经过多方考虑后,我决定让它全屏。我使用的是Chrome,并尝试使用$("container").webkitRequestFullScreen();
,但它无法正常工作,即使将文件复制到本地主机服务器也是如此。
有什么我失踪了吗?我的代码错了吗?这里是:JavaScript全屏API无法正常工作...?
var cont = $("container");
if (cont.requestFullscreen) {
cont.requestFullscreen();
}
if (cont.webkitRequestFullscreen) {
cont.webkitRequestFullscreen();
}
if (cont.mozRequestFullscreen) {
cont.mozRequestFullscreen();
}
if (cont.msRequestFullscreen) {
cont.msRequestFullscreen();
}
这就是我的代码。 cont
是对我的容器div的引用。
在此先感谢!
编辑:我一直忘记提及这个 - 我的$
函数不是jQuery,它只是返回document.getElementById(id);
。
编辑2:尽管什么StackOverflow说,我没有使用IE浏览器!我甚至不需要IE支持!
甲jQuery对象不具有任何种类的requestFullscreen'方法的'。 DOM对象。尝试'cont.get(0).requestFullScreen()'。 – apsillers
本文介绍如何使用requestFullScreen以及如何处理各种浏览器的错误 - 希望它有所帮助! http://sorcery.smugmug.com/2012/06/06/using-html5s-fullscreen-api-for-fun-and-profit/ – flauntster
对不起,我没有使用jQuery。我会在我的OP中指定。我正在使用一个简单的'document.getElementById'函数。 – Atutouato