/** 监听用户切屏次数 */
handleScreen() {
let _this = this
_this.num = 0
window.onblur = function() {
_this.num++
}
window.onfocus = function() {
if (_this.num === 3) {
_this.$message.info('已离开当前页面' + _this.num + '次,离开5次将强制交卷')
}
if (_this.num > 5) {
_this.$dialog.alert({
title: '提示',
message: '由于您离开次数过多,将强制交卷'
}).then(() => {
window.onblur = function() {
// 这里初始化次数,销毁监听
_this.num = 0
}
_this.autoSubmit()
})
}
}
},
监听窗口失焦来监听窗口切屏,并销毁监听
最新推荐文章于 2024-05-24 10:06:19 发布