在HTML5中,W3C制定了關(guān)于全屏的API但是只能由用戶事件觸發(fā)(可以是鼠標(biāo)事件,鍵盤事件等),所以不能自動(dòng)全屏;
最近做這一塊挺惡心的,非要實(shí)現(xiàn)跳轉(zhuǎn)出來的頁面自動(dòng)實(shí)現(xiàn)F11效果终佛,卡死。雾家。铃彰。
來一段網(wǎng)上收集的全屏效果代碼,隨意點(diǎn)擊一下全屏【ie芯咧,chrome已經(jīng)試過牙捉,其他沒試】
<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<meta?name="viewport"?content="width=device-width,?initial-scale=1.0">
????<title>Document</title>
</head>
<body?onclick="openFullscreen()">
????<div>
????????整個(gè)body區(qū)域隨意點(diǎn)擊一下吧
????</div>
????<script>
????????//全屏
????????function?openFullscreen()?{
????????????var?element?=?document.documentElement;
????????????if?(element.requestFullscreen)?{
????????????????element.requestFullscreen();
????????????}?else?if?(element.mozRequestFullScreen)?{
????????????????element.mozRequestFullScreen();
????????????}?else?if?(element.msRequestFullscreen)?{
????????????????element.msRequestFullscreen();
????????????}?else?if?(element.webkitRequestFullscreen)?{
????????????????element.webkitRequestFullScreen();
????????????}
????????}
????</script>
</body>
</html>