因此,我正在製作一款遊戲,經過多方考慮後,我決定讓它全屏。我使用的是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