当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。