这里实现的全屏和退出全屏是模仿按下F11。
1.全屏
1 function fullScreen(){ 2 var el = document.documentElement; 3 var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen; 4 5 //typeof rfs != "undefined" && rfs 6 if (rfs) { 7 rfs.call(el); 8 } 9 else if (typeof window.ActiveXObject !== "undefined") { 10 //for IE,这里其实就是模拟了按下键盘的F11,使浏览器全屏 11 var wscript = new ActiveXObject("WScript.Shell"); 12 if (wscript != null) { 13 wscript.SendKeys("{F11}"); 14 } 15 } 16 }
2.退出全屏
1 function exitScreen(){ 2 var el = document; 3 var cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen; 4 5 //typeof cfs != "undefined" && cfs 6 if (cfs) { 7 cfs.call(el); 8 } 9 else if (typeof window.ActiveXObject !== "undefined") { 10 //for IE,这里和fullScreen相同,模拟按下F11键退出全屏 11 var wscript = new ActiveXObject("WScript.Shell"); 12 if (wscript != null) { 13 wscript.SendKeys("{F11}"); 14 } 15 } 16 }
3.当然了为了实现全屏效果一般还得添加一个类
1 .full{ 2 position: fixed!important; 3 z-index: 10000; 4 100%!important; 5 height: 100%!important; 6 top: 0; 7 left: 0; 8 }