CSS网页全屏



<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
	<title>全屏</title>
</head>

<body >
	<style>
		 #fullscreen{
			width:40px;
			height:40px;
			position:fixed;
			top:20px;
			right:20px;
			opacity:0.4;
		 }
     </style>
	<div id="fullscreen" fullflag ="0">全屏</div>
		
	<script>
    
	document.getElementById("fullscreen").onclick=function(){
	    //var elem = document.getElementById("content");
	    //var h1 = document.getElementById("h1");
	    //requestFullScreen(elem);// 某个页面元素
		
		var flag =this.getAttribute("fullflag");
		if(flag == 0){
			
			requestFullScreen(document.documentElement);// 整个网页
			this.innerHTML= "退出";	
			this.setAttribute("fullflag",'1');
		}else{
			this.innerHTML="全屏";	
			this.setAttribute("fullflag",'0');
			exitFull()
			
		}
	    
	};

	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>
</body>
</html>
	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值