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

快乐打工仔 分类:实例代码

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

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

代码如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.pipipi.net/" />
<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>本站的地址是pipipi.net</h1>    
</div>  
</div>    
</body>      
</html>

回复

我来回复
  • 暂无回复内容