浏览器全屏与退出全屏的方法

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 全屏
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}')
}
}
}