1. 程式人生 > >IE瀏覽器不能使用window.open()的解決方案

IE瀏覽器不能使用window.open()的解決方案

1.判斷瀏覽器是否為IE

var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字串  

var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判斷是否IE<11瀏覽器  

if(isIE){

//如果為IE 構造一個虛擬的a標籤 以便於跳轉到對應的URL

   var gotolink = document.createElement('a');
   gotolink.href = url;
   gotolink.setAttribute("target", "_blank");
   document.body.appendChild(gotolink);
   gotolink.click();
}
else{
var targetWndName = "middleWin";
var wnd = window.open("", targetWndName);
var link = document.getElementById("thinkLink");
link.target = targetWndName;
link.href = url;
link.click();
}