<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>全屏</title>
</head>
<body>
<input type="button" "aa()" value="全屏/取消全屏">
<input type="button" "t()" value="查询状态">
</body>
<script>
function t() {
var tof1= fullScreen.isToF();
console.log(tof1);
}
function aa() {
var tof=fullScreen.isFullscreen();
console.log(tof);
}
var fullScreen={
isFullscreen:function(){
var that=this;
var tof=that.isToF();//判断是否全屏
if(tof!=false){
that.exit();//取消全屏
return true;
}else if(tof==false){
that.screen();//全屏
return false;
}
},
isToF:function(){
var tof= document.fullscreenElement ||
document.msFullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement || false;
if(tof==false){
return false;
}else{
return true;
}
},
ActiveXObject:function(){
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
},
screen:function () {
var el = document.documentElement;
var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;
if(typeof rfs != "undefined" && rfs) {
rfs.call(el);
} else if(typeof window.ActiveXObject != "undefined") { //判断是否IE浏览器
this.ActiveXObject();
}
},
exit:function () {
// 判断各种浏览器,找到正确的方法
var exitMethod = document.exitFullscreen || document.mozCancelFullScreen || document.webkitExitFullscreen || document.webkitExitFullscreen;
if (exitMethod) {
exitMethod.call(document);
}
else if (typeof window.ActiveXObject !== "undefined") { //判断是否IE浏览器
//判断是否IE浏览器
this.ActiveXObject();
}
}
}
</script>
</html>
封装一个网页全屏控制及查询功能
最新推荐文章于 2024-02-26 10:38:09 发布