浏览器全屏与退出全屏的方法 Posted on 2018-06-04 | In 前端 | Words count in article: 168 代码如下: 12345678910111213141516171819202122232425262728293031// 全屏fullScreen() { this.$store.state.app.fullscreen = true 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') { // for IE,这里其实就是模拟了按下键盘的F11,使浏览器全屏 // eslint-disable-next-line var wscript = new ActiveXObject('WScript.Shell') if (wscript != null) { wscript.SendKeys('{F11}') } }}//退出全屏exitFull() { this.$store.state.app.fullscreen = false // 判断各种浏览器,找到正确的方法 var exitMethod = document.exitFullscreen || document.mozCancelFullScreen || document.webkitExitFullscreen || document.webkitExitFullscreen if (exitMethod) { exitMethod.call(document) } else if (typeof window.ActiveXObject !== 'undefined') { // for Internet Explorer // eslint-disable-next-line var wscript = new ActiveXObject('WScript.Shell') if (wscript !== null) { wscript.SendKeys('{F11}') } }}