JS判断浏览器类型的方法总结(IE firefox chrome opera safari)

 
更多

JS判断浏览器类型的方法总结,可判别当前客户端所使用的浏览器是ie,firefox,safari,chrome或者是opera,另外js可以精确判断到ie浏览器的版本,依然直接上代码,需要的朋友可按照自己的要求进行修改。

第一种方法:

var Browser=new Object();
Browser.isMozilla=(typeof document.implementation!='undefined')&&(typeof document.implementation.createDocument!='undefined')&&(typeof HTMLDocument!='undefined');
Browser.isIE=window.ActiveXObject ? true : false;
Browser.isFirefox=(navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isSafari=(navigator.userAgent.toLowerCase().indexOf("safari")!=-1);
Browser.isOpera=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
function check(){
	alert(Browser.isIE?'ie':'not ie');
	alert(Browser.isFirefox?'Firefox':'not Firefox');
	alert(Browser.isSafari?'Safari':'not Safari');
	alert(Browser.isOpera?'Opera':'not Opera');
}
window.onload=check;

 第二种方法:

function isBrowser(){
	var Sys={};
	var ua=navigator.userAgent.toLowerCase();
	var s;
	(s=ua.match(/msie ([\d.]+)/))?Sys.ie=s[1]:
	(s=ua.match(/firefox\/([\d.]+)/))?Sys.firefox=s[1]:
	(s=ua.match(/chrome\/([\d.]+)/))?Sys.chrome=s[1]:
	(s=ua.match(/opera.([\d.]+)/))?Sys.opera=s[1]:
	(s=ua.match(/version\/([\d.]+).*safari/))?Sys.safari=s[1]:0;
	if(Sys.ie){//Js判断为IE浏览器
		alert('http://www.phpernote.com'+Sys.ie);
		if(Sys.ie=='9.0'){//Js判断为IE 9
		}else if(Sys.ie=='8.0'){//Js判断为IE 8
		}else{
		}
	}
	if(Sys.firefox){//Js判断为火狐(firefox)浏览器
		alert('http://www.phpernote.com'+Sys.firefox);
	}
	if(Sys.chrome){//Js判断为谷歌chrome浏览器
		alert('http://www.phpernote.com'+Sys.chrome);
	}
	if(Sys.opera){//Js判断为opera浏览器
		alert('http://www.phpernote.com'+Sys.opera);
	}
	if(Sys.safari){//Js判断为苹果safari浏览器
		alert('http://www.phpernote.com'+Sys.safari);
	}
}

另外关于如何使用jquery php判断浏览器类型可参照如下两篇文章:

PHP判断浏览器类型

jquery获取浏览器类型和版本号的方法

打赏

本文固定链接: https://www.cxy163.net/archives/4027 | 绝缘体

该日志由 绝缘体.. 于 2013年06月04日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: JS判断浏览器类型的方法总结(IE firefox chrome opera safari) | 绝缘体
关键字: , , , ,

JS判断浏览器类型的方法总结(IE firefox chrome opera safari):等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter