I m tring to detect browser using javascript in my facebook application. I m using following code:
if(navigator.appName == "Microsoft Internet Explorer") { //do somthig }
but this code is not working. Please help m开发者_JAVA百科e.
The following js code is from vbb
var userAgent=navigator.userAgent.toLowerCase();
var is_opera=((userAgent.indexOf("opera")!=-1)||(typeof (window.opera)!="undefined"));
var is_saf=((userAgent.indexOf("applewebkit")!=-1)||(navigator.vendor=="Apple Computer, Inc."));
var is_webtv=(userAgent.indexOf("webtv")!=-1);
var is_ie=((userAgent.indexOf("msie")!=-1)&&(!is_opera)&&(!is_saf)&&(!is_webtv));
var is_ie4=((is_ie)&&(userAgent.indexOf("msie 4.")!=-1));
var is_ie7=((is_ie)&&(userAgent.indexOf("msie 7.")!=-1));
var is_ie8=((is_ie)&&(userAgent.indexOf("msie 8.")!=-1));
var is_ps3=(userAgent.indexOf("playstation 3")!=-1);
var is_moz=((navigator.product=="Gecko")&&(!is_saf));
var is_kon=(userAgent.indexOf("konqueror")!=-1);
var is_ns=((userAgent.indexOf("compatible")==-1)&&(userAgent.indexOf("mozilla")!=-1)&&(!is_opera)&&(!is_webtv)&&(!is_saf));
var is_ns4=((is_ns)&&(parseInt(navigator.appVersion)==4));
var is_mac=(userAgent.indexOf("mac")!=-1);
Recently had to Identity IE to remove something only for IE and figured out IE11 doesnt identify itself as IE.
Here is a safe code to identify IE all versions
function isIE() {
return typeof MSStyleCSSProperties !== "undefined";
}
精彩评论