0
点赞
收藏
分享

微信扫一扫

Vue进阶(六十八):JS 判断当前浏览器是否为 IE 及 关于js中页面跳转的用法 及 隐藏浏览器地址栏参数或者将整个地址栏都隐藏只显示根目录

(文章目录) <hr style=" border:solid; width:100px; height:1px;" color=#000000 size=1">

一、方式一

<!--[if IE 6]>仅IE6可识别<![endif]-->
<!--[if lte IE 6]> IE6及其以下版本可识别<![endif]-->
<!--[if lt IE 6]> IE6以下版本可识别<![endif]-->
<!--[if gte IE 6]> IE6及其以上版本可识别<![endif]-->
<!--[if gt IE 6]> IE6以上版本可识别<![endif]-->
<!--[if IE]> 所有的IE可识别<![endif]-->
<!--[if !IE]><!--> 除IE外都可识别<!--<![endif]-->

二、方式二

function isIE(){
	if (window.navigator.userAgent.indexOf("MSIE")>=1) 
		return true; 
	else
		return false; 
}

三、方式三

这个方法,edge浏览器中为false,ie11中为false

function isIE() { //ie?
 if (!!window.ActiveXObject || "ActiveXObject" in window)
  	return true;
  else
 	 return false;
 }

四、方式四

这个方法,edge浏览器中为false,ie11为true

function IEVersion() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if(isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if(fIEVersion == 7) {
            return 7;
        } else if(fIEVersion == 8) {
            return 8;
        } else if(fIEVersion == 9) {
            return 9;
        } else if(fIEVersion == 10) {
            return 10;
        } else {
            return 6;//IE版本<=7
        }   
    } else if(isEdge) {
        return 'edge';//edge
    } else if(isIE11) {
        return 11; //IE11  
    }else{
        return -1;//不是ie浏览器
    }
}

"window.location.href"、"location.href"是本页面跳转.

"parent.location.href" 是上一层页面跳转.

"top.location.href" 是最外层的页面跳转.

举例说明:

如果A,B,C,D都是html,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js这样写

"window.location.href"、"location.href":D页面跳转

"parent.location.href":C页面跳转

"top.location.href":A页面跳转

如果D页面中有form的话,

<form>:  form提交后D页面跳转

<form target="_blank">:  form提交后弹出新页面

<form target="_parent">:  form提交后C页面跳转

<form target="_top"> :  form提交后A页面跳转

如果访问的是iframe里面的页面,重新加载最外层的页面

<html>
<head>
<title></title>
<script language="javascript">
function escapeFrame(){
  if (window.top.location.href != window.location.href) {
    window.top.location.reload();
  }
}
</script>
</head>

<body onload="escapeFrame()">
<iframe src="b.html" ></iframe>
</body>
</html>

在使用Vue进行前端项目开发过程中,会遇到出于安全考虑,浏览器地址栏禁止显示方法参数的需求。以下方法可实现以上需求。 注:该方法存在页面刷新方法参数无法获取问题,需要另作处理(例如sessionStorage)。 在这里插入图片描述

举报

相关推荐

0 条评论