IE8跳转谷歌浏览器亲测有效
废话不多说直接上代码。
// 直接将代码放到public 的 index.html就ok了
<script type="text/javascript">
//验证是否时IE
function checkIE() {
var isIE = true;
if (navigator && navigator.userAgent) {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
isIE = (userAgent.indexOf("compatible") > -1 && (userAgent.indexOf("MSIE 6.0") > -1 || userAgent.indexOf("MSIE 7.0") > -1 || userAgent.indexOf("MSIE 8.0") > -1 || userAgent.indexOf("MSIE 9.0") > -1)); //判断是否IE浏览器
}
if (isIE) {
return true;
}
return false;
}
(function(){
if (checkIE()) { //判断是否是IE浏览器
var url = window.location.protocol + '//'+ window.location.host;
url = url.toString().replace(/\&/g, '\^\&');
// 这样写就不会报错了 ActiveXObject is not definde(这个单词可能错了哈)
if(window.ActiveXObject){
ws = new ActiveXObject("WScript.Shell");
ws.Run('cmd.exe /c start chrome' + ' ' + url , 0, true);
this.window.close();
}
}
}())
</script>