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---F12
	       if (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.clientHeight
	console.log(width,height,'宽高');
	return {width:width,height:height}
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值