UserAgent是浏览器用于 HTTP 请求的用户代理头的值
window.close()方法在Chrome浏览器中不好用。
先是使用navigator.appName方法。
但是IE之外的浏览器(Safari,FireFox,Chrome)显示的都是Netscape
这种方法,无法单独区分Chrome浏览器。
解决:
使用navigator.userAgent;
看看在这里面能否找到Chrome关键字。
具体使用的代码:
if(navigator.userAgent.indexOf("Chrome") == -1){
window.close();
}else{
// 可以找到Chrome,表明是Chrome浏览器。
window.open('','_self','');
window.close();
}
//判断是否是ie,因为现在的ie11没有msie,所以判断ie不能用document.all,ie10下的都是1,其他浏览器都是0
if(!!window .ActiveXObject || "ActiveXObject" in window){
var ie6 = navigator.userAgent .indexOf ("MSIE 6.0")>0 ;
var ie7 = navigator.userAgent .indexOf ("MSIE 7.0")>0 ;
var ie8 = navigator.userAgent .indexOf ("MSIE 8.0")>0 ;
var ie9 = navigator.userAgent .indexOf ("MSIE 9.0")>0 ;
var ie5 = navigator.userAgent .indexOf ("MSIE 5.0")>0 ;
//ie9及以下不调用动态显示,不支持websocket
if(!ie6 + !ie7 + !ie8 + !ie9+ !ie5 == 5){
webSocketPolling ();
}
}