• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

JS 全屏和退出全屏详解及实例代码

php 搞代码 4年前 (2022-01-04) 23次浏览 已收录 0个评论

JS 全屏和退出全屏

js实现浏览器窗口全屏和退出全屏的功能,市面上主流浏览器如:谷歌、火狐、360等都是兼容的,不过IE低版本有点瑕疵(全屏状态下仍

来源gao!%daima.com搞$代*!码网

有底部的状态栏)。

这个demo基本是够了,直接复制下面的源码另存为html文件看效果吧。

<!DOCTYPE html><html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>js全屏和退出全屏代码</title><body><!-- requestFullScreen(document.documentElement): 整个网页进入全屏   requestFullScreen(document.getElementById("video-box")): 指定某块区域全屏 --><button onclick="requestFullScreen(document.documentElement)">全屏显示</button><button onclick="exitFull()">退出全屏</button></body><script type="text/javascript">function requestFullScreen(element) {  // 判断各种浏览器,找到正确的方法  var requestMethod = element.requestFullScreen || //W3C  element.webkitRequestFullScreen ||  //Chrome等  element.mozRequestFullScreen || //FireFox  element.msRequestFullScreen; //IE11  if (requestMethod) {    requestMethod.call(element);  }  else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer    var wscript = new ActiveXObject("WScript.Shell");    if (wscript !== null) {      wscript.SendKeys("{F11}");    }  }}

//退出全屏 判断浏览器种类

function exitFull() {  // 判断各种浏览器,找到正确的方法  var exitMethod = document.exitFullscreen || //W3C  document.mozCancelFullScreen ||  //Chrome等  document.webkitExitFullscreen || //FireFox  document.webkitExitFullscreen; //IE11  if (exitMethod) {    exitMethod.call(document);  }  else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer    var wscript = new ActiveXObject("WScript.Shell");    if (wscript !== null) {      wscript.SendKeys("{F11}");    }  }}</script></html>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:JS 全屏和退出全屏详解及实例代码
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址