- 全屏
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.a {
margin:0 auto;
height:600px;
width:700px;
}
.content {
margin:0 auto;
height:500px;
width:700px;
background:#900;
}
</style>
<body>
<div class="a">
<button id="btn">js控制页面的全屏展示</button>
<div class="content" id="content">
<h1 id="h1">js控制页面的全屏展示和退出全屏显示</h1>
<button id="btn" onclick="exitFull()">js控制页面的退出全屏显示</button>
</div>
</div>
</body>
<script type="text/javaScript">
document.getElementById("btn").onclick=function(){
var elem = document.getElementById("content");
var h1 = document.getElementById("h1");
requestFullScreen(elem);// 某个页面元素
// requestFullScreen(document.documentElement);// 整个网页
};
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>