2015-03-19 68 views
0

我想要當我的網頁加載它將自動全屏,而不點擊body.You可以看看我的網站,我想進行更改:TV。當你在任何地方點擊它時,它將全屏顯示。但是我想在不點擊任何東西的情況下自動全屏顯示。我想知道如果我可以使用自動點擊來改變onClick身體?因爲使用onload什麼也沒有發生。你可以幫我嗎?如何使自動點擊?

我只在我的html文檔中使用<body onclick="toggleFullScreen()">

這是toggleFullScreen的JavaScript的:

function errorHandler() { 
 
    alert('mozfullscreenerror'); 
 
} 
 
document.documentElement.addEventListener('mozfullscreenerror', errorHandler, false); 
 

 
// toggle full screen 
 

 
function toggleFullScreen() { 
 
    if (!document.fullscreenElement && // alternative standard method 
 
     !document.mozFullScreenElement && !document.webkitFullscreenElement) { // current working methods 
 
    if (document.documentElement.requestFullscreen) { 
 
     document.documentElement.requestFullscreen(); 
 
    } else if (document.documentElement.mozRequestFullScreen) { 
 
     document.documentElement.mozRequestFullScreen(); 
 
    } else if (document.documentElement.webkitRequestFullscreen) { 
 
     document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); 
 
    } 
 
    } else { 
 
    if (document.cancelFullScreen) { 
 
     document.cancelFullScreen(); 
 
    } else if (document.mozCancelFullScreen) { 
 
     document.mozCancelFullScreen(); 
 
    } else if (document.webkitCancelFullScreen) { 
 
     document.webkitCancelFullScreen(); 
 
    } 
 
    } 
 
}

+0

這是不可能的。看到這裏=> [http://stackoverflow.com/questions/11567993/is-possible-automatic-fullscreen-with-html5](http://stackoverflow.com/questions/11567993/is-possible-automatic-fullscreen-與-html5) – lshettyl 2015-03-19 06:34:31

回答

0

把它像這樣標記之前,

<script> 
$(document).ready(function(){ 
toggleFullScreen(); 
}); 
</script> 
+0

這個答案有語法錯誤....;) – Jai 2015-03-19 06:40:28

+0

@Jai oops對不起,錯誤的語法 – 2015-03-19 06:42:10

0

如果你想堅持到JavaScript,然後試試這個。

<script type="text/javascript"> 
window.onload = maxWindow; 

function maxWindow() { 
    window.moveTo(0, 0); 


    if (document.all) { 
     top.window.resizeTo(screen.availWidth, screen.availHeight); 
    } 

    else if (document.layers || document.getElementById) { 
     if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) { 
      top.window.outerHeight = screen.availHeight; 
      top.window.outerWidth = screen.availWidth; 
     } 
    } 
} 

</script> 
+0

它不工作..我以前試過 – hendraspt 2015-03-19 07:02:13