浏览器内核:
浏览器最核心部分称之为"Rendering Engine",又称“渲染引擎”,我们通常叫浏览器内核。
浏览器内核决定了浏览器如何显示网页的内容以及页面的格式信息。
内核分类:
1、Trident(IE内核):使用IE内核的浏览器有IE6/IE7/IE8(Trident 4.0). IE9(Trident 5.0). IE10(Trident 10.0)。当然像国内的很多浏览器使用了IE内核但是并非IE浏览器(壳浏览器)。如:360安全浏览器(1.0-5.0使用Trident),6.0使用Trident+WebKit,7.0使用Trident+Blink;猎豹浏览器,遨游浏览器,搜狗高速浏览器等。
有很多浏览器现在称作为“双核”或“多核”,其中一个内核使用Trident,后增加另外一个内核,国内称之为“高速浏览器模式”。Trident则用来做兼容模式。
2、Gekco(Firefox内核):Firefox浏览器等。
3、Presto(Opera早期版本):现在已经废弃。
4、Webkit(Safari内核,Chrome内核):苹果公司的内核,也是苹果的Safari浏览器内核,如Chrome、Safari、360极速浏览器以及搜狗浏览器高速模式中使用了该内核。
5、Blink:是Google和Opera software开发的浏览器排版引擎,在Chrome的28版本之后使用、Opera 15版本后使用。
排版引擎:
1、Webcore:苹果公司研发,使用Webcore的主要浏览器是Safari。
2、KHTML。
javascript获取客户端信息:
navigator包含了浏览器的信息。
对象属性(列举比较常用的几个):
1、appVersion:返回浏览器的平台和版本信息。
2、platform:返回运行浏览器的操作平台的名称。
3、userAgent:返回由客户机发送服务器的user-agent头部的值。
各个浏览器userAgent展示:
Firefox:gecko为使用内核,后面为版本号20100101。也可通过后面的firefox判定是否为火狐浏览器,版本号为35.0。
Opera:版本不同,可能结果不同:
IE9.0:可以通过msie判定是否为IE浏览器。
Chrome:
Safari:
国内浏览器支持不完善:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
</body>
<script type="text/javascript">
/**
* 获取浏览器类型以及版本号
* 支持国产浏览器:猎豹浏览器、搜狗浏览器、傲游浏览器、360极速浏览器、360安全浏览器、
* QQ浏览器、百度浏览器等.
* 支持国外浏览器:IE,Firefox,Chrome,safari,Opera等.
* 使用方法:
* 获取浏览器版本:Browser.client.version
* 获取浏览器名称(外壳):Browser.client.name
* @author:xuzengqiang
* @since :2015-1-27 10:26:11
**/
var Browser=Browser || (function(window){
var document = window.document,
navigator = window.navigator,
agent = navigator.userAgent.toLowerCase(),
//IE8+支持.返回浏览器渲染当前文档所用的模式
//IE6,IE7:undefined.IE8:8(兼容模式返回7).IE9:9(兼容模式返回7||8)
//IE10:10(兼容模式7||8||9)
IEMode = document.documentMode,
//chorme
chrome = window.chrome || false,
System = {
//user-agent
agent : agent,
//是否为IE
isIE : /msie/.test(agent),
//Gecko内核
isGecko: agent.indexOf("gecko")>0 && agent.indexOf("like gecko")<0,
//webkit内核
isWebkit: agent.indexOf("webkit")>0,
//是否为标准模式
isStrict: document.compatMode === "CSS1Compat",
//是否支持subtitle
supportSubTitle:function(){
return "track" in document.createElement("track");
},
//是否支持scoped
supportScope:function(){
return "scoped" in document.createElement("style");
},
//获取IE的版本号
ieVersion:function(){
try {
return agent.match(/msie ([\d.]+)/)[1] || 0;
} catch(e) {
console.log("error");
return IEMode;
}
},
//Opera版本号
operaVersion:function(){
try {
if(window.opera) {
return agent.match(/opera.([\d.]+)/)[1];
} else if(agent.indexOf("opr") > 0) {
return agent.match(/opr\/([\d.]+)/)[1];
}
} catch(e) {
console.log("error");
return 0;
}
},
//描述:version过滤.如31.0.252.152 只保留31.0
versionFilter:function(){
if(arguments.length === 1 && typeof arguments[0] === "string") {
var version = arguments[0];
start = version.indexOf(".");
if(start>0){
end = version.indexOf(".",start+1);
if(end !== -1) {
return version.substr(0,end);
}
}
return version;
} else if(arguments.length === 1) {
return arguments[0];
}
return 0;
}
};
try {
//浏览器类型(IE、Opera、Chrome、Safari、Firefox)
System.type = System.isIE?"IE":
window.opera || (agent.indexOf("opr") > 0)?"Opera":
(agent.indexOf("chrome")>0)?"Chrome":
//safari也提供了专门的判定方式
window.openDatabase?"Safari":
(agent.indexOf("firefox")>0)?"Firefox":
'unknow';
//版本号
System.version = (System.type === "IE")?System.ieVersion():
(System.type === "Firefox")?agent.match(/firefox\/([\d.]+)/)[1]:
(System.type === "Chrome")?agent.match(/chrome\/([\d.]+)/)[1]:
(System.type === "Opera")?System.operaVersion():
(System.type === "Safari")?agent.match(/version\/([\d.]+)/)[1]:
"0";
//浏览器外壳
System.shell=function(){
//遨游浏览器
if(agent.indexOf("maxthon") > 0) {
System.version = agent.match(/maxthon\/([\d.]+)/)[1] || System.version ;
return "傲游浏览器";
}
//QQ浏览器
if(agent.indexOf("qqbrowser") > 0) {
System.version = agent.match(/qqbrowser\/([\d.]+)/)[1] || System.version ;
return "QQ浏览器";
}
//搜狗浏览器
if( agent.indexOf("se 2.x")>0) {
return '搜狗浏览器';
}
//Chrome:也可以使用window.chrome && window.chrome.webstore判断
if(chrome && System.type !== "Opera") {
var external = window.external,
clientInfo = window.clientInformation,
//客户端语言:zh-cn,zh.360下面会返回undefined
clientLanguage = clientInfo.languages;
//猎豹浏览器:或者agent.indexOf("lbbrowser")>0
if( external && 'LiebaoGetVersion' in external) {
return '猎豹浏览器';
}
//百度浏览器
if (agent.indexOf("bidubrowser")>0) {
System.version = agent.match(/bidubrowser\/([\d.]+)/)[1] ||
agent.match(/chrome\/([\d.]+)/)[1];
return "百度浏览器";
}
//360极速浏览器和360安全浏览器
if( System.supportSubTitle() && typeof clientLanguage === "undefined") {
//object.key()返回一个数组.包含可枚举属性和方法名称
var storeKeyLen = Object.keys(chrome.webstore).length,
v8Locale = "v8Locale" in window;
return storeKeyLen > 1? '360极速浏览器':'360安全浏览器';
}
return "Chrome";
}
return System.type;
};
//浏览器名称(如果是壳浏览器,则返回壳名称)
System.name = System.shell();
//对版本号进行过滤过处理
System.version = System.versionFilter(System.version);
} catch(e) {
console.log("error");
}
return {
client:System
};
})(window);
alert(Browser.client.name+" "+Browser.client.version);
</script>
</html>