當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


HTML DOM exitFullscreen()用法及代碼示例


exitFullscreen()方法請求將當前處於全屏模式的元素從全屏模式中取出。如果element不在全屏模式,則什麽都不會改變。此方法的反向是requestFullscreen()。

用法:

HTMLElementObject.exitFullscreen()

參數:無需參數。


返回值:沒有返回值。

例:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
      HTML | DOM exitFullscreen() Method 
    </title> 
  
    <!--script for close and open fullscreen-->
    <script> 
        var elem = document.documentElement; 
  
        function closeFullscreen() { 
            if (document.exitFullscreen) 
                document.exitFullscreen(); 
        } 
  
        function openFullscreen() { 
            if (elem.requestFullscreen) 
                elem.requestFullscreen(); 
        } 
    </script> 
</head> 
  
<body> 
  
    <h2>Welcome to GeeksforGeeks</h2> 
    <p> 
      Click on the "Open Fullscreen" button to open this page in"  
      + "fullscreen mode. Close it by either clicking the "Esc" key" 
      +" on your keyboard, or with the "Close Fullscreen" button. 
    </p> 
  
    <button onclick="openFullscreen();"> 
      Open Fullscreen 
    </button> 
    <button onclick="closeFullscreen();"> 
      Close Fullscreen 
    </button> 
  
</body> 
  
</html>

輸出:
全屏打開

退出全屏

支持的瀏覽器:下麵列出了DOM exitFullscreen()方法支持的瀏覽器:

  • 穀歌瀏覽器
  • IE瀏覽器
  • 火狐瀏覽器
  • Opera
  • 蘋果瀏覽器


相關用法


注:本文由純淨天空篩選整理自ProgrammerAnvesh大神的英文原創作品 HTML | DOM exitFullscreen() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。