您的位置:首页 > 教程笔记 > 前端笔记

javascript实现的控制浏览器全屏效果 [

2023-12-04 13:46:52 前端笔记 32

点击F11键能够实现浏览器的全屏效果。

当然这个效果也是可以用js实现,下面就是相关代码,需要的朋友可以做一下参考。

代码:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="/" />
<title>实例</title>
<style>
div{
  margin:0 auto;
  height:600px;
  width:700px;
}
#content{
  margin:0 auto;
  height:500px;
  width:700px; 
  background:#ccc;
}
</style>
<script>
function requestFullScreen(element){    
  var requestMethod=element.requestFullScreen 
  || element.webkitRequestFullScreen 
  || element.mozRequestFullScreen 
  || element.msRequestFullScreen;    
  if(requestMethod){      
    requestMethod.call(element);    
  } 
  else if (typeof window.ActiveXObject !== "undefined"){      
    var wscript = new ActiveXObject("WScript.Shell");    
    if (wscript !== null) {    
      wscript.SendKeys("{F11}");    
    }    
  }    
}  
window.onload=function(){
  document.getElementById("btn").onclick=function(){     
    var elem = document.getElementById("content");      
    requestFullScreen(elem);     
  };  
}  
</script>  
</head>   
<body>    
<div>  
<button id="btn">查看效果</button>    
<div id="content">  
  <h1>本站的地址是实例3</h1>    
</div>  
</div>    
</body>      
</html>

相关推荐