700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > vue封装的 全屏js 禁止键盘事件 获取当前浏览器类型 获取当前的屏幕宽高

vue封装的 全屏js 禁止键盘事件 获取当前浏览器类型 获取当前的屏幕宽高

时间:2022-05-04 21:27:15

相关推荐

vue封装的 全屏js 禁止键盘事件 获取当前浏览器类型 获取当前的屏幕宽高

开启全屏

export function fullScreen(){var el = document.documentElement,rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen,wscript;if(typeof rfs != "undefined" && rfs) {rfs.call(el);return;}if(typeof window.ActiveXObject != "undefined") {wscript = new ActiveXObject("WScript.Shell");if(wscript) {wscript.SendKeys("{F11}");}}}

禁止键盘事情 Esc 和 F11 是禁不掉的

//禁止键盘事件export function stopKeyDownThing(){document.onkeydown = function(e) {var evt = window.event || e;var code = evt.keyCode || evt.which;//屏蔽F1---F12if (code > 111 && code < 124) {if (evt.preventDefault) {evt.preventDefault();} else {evt.keyCode = 0;evt.returnValue = false;}}if (code == 27) {if (evt.preventDefault) {evt.preventDefault();} else {evt.keyCode = 0;evt.returnValue = false;}}};//禁止鼠标右键菜单document.oncontextmenu = function(e) {return false;};//阻止后退的所有动作,包括 键盘、鼠标手势等产生的后退动作。history.pushState(null, null, window.location.href);window.addEventListener("popstate", function() {history.pushState(null, null, window.location.href);});}

获取当前浏览器

/ 获取当前登录的浏览器export function getNowBrowser(){var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串// console.log("loginuserAgent:", userAgent)//判断是否Opera浏览器if (userAgent.indexOf("Opera") > -1) {return "Opera"};//判断是否Edge浏览器if (userAgent.indexOf("Edg") > -1){return 'Edge'}//判断是否Firefox浏览器if (userAgent.indexOf("Firefox") > -1) {return "firefox";}//判断是否Chrome浏览器if (userAgent.indexOf("Chrome") > -1){return "Chrome";}//判断是否Safari浏览器if (userAgent.indexOf("Safari") > -1) {return "Safari";}//判断是否IE浏览器if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {return "IE";}if ( userAgent.indexOf("Trident") > -1){return "IE";}}

获取当前屏幕宽高

// 获取当前浏览器的屏幕宽高export function getCurrentScreen(){let width= window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;let height= window.innerHeight || document.documentElement.clientHeight || document.body.clientHeightconsole.log(width,height,'宽高');return {width:width,height:height}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。