JavaScript实现全屏显⽰<!doctype html>
<html>
<head>
<title>全屏显⽰</title>
<meta charset="utf-8" />
<style>
div {
width: 200px;
height:200px;
background:pink;
margin:100px auto;
}
button {
margin-left: 650px;
}
h1 {
margin-left: 400px;
}
</style>
html实现用户注册登录代码</head>
<body>
<h1>js控制页⾯的全屏展⽰和退出全屏显⽰</h1>
<div id="div1"></div>
<button type="button" id="btn">全屏</button>
</body>
</html>
⽅法⼀:
<script type="text/javascript">
var elem =ElementById("div1");
requestFullScreen(elem);
}
var requestFullScreen=function(element) {
//某个元素有请求
var requestMethod =questFullScreen
||element.webkitRequestFullScreen //⾕歌
||RequestFullScreen //⽕狐
||element.msRequestFullScreen; //IE11
if (requestMethod) {
requestMethod.call(element); //执⾏这个请求的⽅法
} else if (typeof window.ActiveXObject !== "undefined") { //window.ActiveXObject判断是否⽀持ActiveX控件 //这⾥其实就是模拟了按下键盘的F11,使浏览器全屏
var wscript = new ActiveXObject("WScript.Shell"); //创建ActiveX
if (wscript !== null) { //创建成功
wscript.SendKeys("{F11}");//触发f11
}
}
}
}
</script>
⽅法⼆:
<script>
var btn = ElementById("btn");
var width = window.screen.width;
var height = window.screen.height;
var elem = ElementById("div1");
requestFullScreen(elem);
}
function requestFullScreen(element) {
if (questFullscreen) {
}
//FireFox
else if (RequestFullScreen) {
}
//Chrome等
else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
//IE11
else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
};
</script>
⽅法三:
<button type="button" id="btn" onclick="window.open(document.location, 'big', 'fullscreen=yes')">全屏</button>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论