说明:window.open(url,"_blank")方法替换如下:
function openUrl(url) {
try {
if (/MSIE\s*(\d+\.\d+);/.test(navigator.userAgent) || /MSIE(\d+\.\d+);/.test(navigator.userAgent) || navigator.userAgent.indexOf('MSIE') >= 0 || navigator.userAgent.indexOf('msie') >= 0) {
var referLink = document.createElement('a');
referLink.href = url;
referLink.target = "_blank";
document.body.appendChild(referLink);
referLink.click();
} else {
var a = $("<a href='" + url + "' target='_blank'>download</a>").get(0);
var e = document.createEvent('MouseEvents');
e.initEvent('click', true, true);
a.dispatchEvent(e);
}
} catch (e) {
window.open(url);
}
}
简单的说就是构造 <a href="#" target="_blank">A标签打开新页</a> 这代码,然后模拟点击事件。这里仅仅是替换window.open()这方法。