JS according to the browser's useagent to determine the type of browser
The UserAgent property is a read-only string that declares the value of the user agent header used by the browser for HTTP requests.
JavaScript syntax: navigator.useragent
PHP Syntax: $_server[' http_user_agent ']
ASP syntax: Request.ServerVariables ("Http_user_agent")
Asp. NET syntax: HttpContext.Current.Request.UserAgent
JSP syntax: Request.getheader ("User-agent")
-------------------------------------------------------
Chrome: (version:50.0.2661.102 m)
jsp:useragent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko)Chrome/50.0.2661.102 safari/537.36
js:useragent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko)Chrome/50.0.2661.102 safari/537.36
-------------------------------------------------------
Firefox: (version:47.0)
jsp:useragent:mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) gecko/20100101Firefox/47.0
js:useragent:mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) gecko/20100101Firefox/47.0
-------------------------------------------------------
Safari: (version:5.1.7)
jsp:useragent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/534.57.2 (khtml, like Gecko)Version/5.1.7Safari/534.57.2
js:useragent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/534.57.2 (khtml, like Gecko) Version/5.1.7Safari/534.57.2
-------------------------------------------------------
IE 8: (version:8.0.7601.17514, update versions:0)
jsp:useragent:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; trident/4.0; SLCC2;. NET CLR 2.0.50727;. NET CLR 3.5.30729;. NET CLR 3.0.30729; Media Center PC 6.0)
js:useragent:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; trident/4.0; SLCC2;. NET CLR 2.0.50727;. NET CLR 3.5.30729;. NET CLR 3.0.30729; Media Center PC 6.0)
-------------------------------------------------------
IE One: (version:11.0.9600.18321 update versions:11.0.31)
jsp:useragent:mozilla/5.0 (Windows NT 6.3; WOW64; trident/7.0; rv:11.0) Like Gecko
js:useragent:mozilla/5.0 (Windows NT 6.3; WOW64; trident/7.0;. net4.0e;. net4.0c;. NET CLR 3.5.30729;. NET CLR 2.0.50727;. NET CLR 3.0.30729; infopath.3; rv:11.0) Like Gecko
-------------------------------------------------------
Windows Edge: (version:25.10580.0.0)
jsp:useragent:mozilla/5.0 (Windows NT 10.0; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/46.0.2486.0 safari/537.36 Edge/13.10586
js:useragent:mozilla/5.0 (Windows NT 10.0; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/46.0.2486.0 safari/537.36 Edge/13.10586
-------------------------------------------------------
[Happy Lai]
Next, how to determine the browser type?
Internet explorer:
Token |
Description |
Edge |
Windows Edge |
trident/7.0 |
IE11 |
trident/6.0 |
Internet Explorer 10 |
trident/5.0 |
Internet Explorer 9 |
trident/4.0 |
Internet Explorer 8 |
JS Code:
Return browser type: "ie", "Firefox", "Chrome", "Opera", "Safari", "Unknow"
Author:aerchi
Site:www.aerchi.com
blog:http://blog.csdn.net/aerchi/article/details/51697592
Email: [Email protected]
Date:2016-06-17
Update:2016-08-11 00:56:00
Call Like:getbrowser (1)
return like "chrome/50.0.2661.102"
Call Like:getbrowser ()
Return like "Chrome"
function Getbrowser (getversion)
{
Note Keyword capitalization
var ua_str = Navigator.userAgent.toLowerCase (), ie_tridents, Trident, Match_str, IE_AER_RV, Browser_chi_type;
Console.log ("article url:http://blog.csdn.net/aerchi/article/details/51697592");
Judging IE browser,
blog:http://blog.csdn.net/aerchi/article/details/51697592
if ("ActiveXObject" in self) {
IE_AER_RV: Indicates the version of IE.
It can affected by the current document mode of IE.
ie_aer_rv= (match_str = Ua_str.match (/msie ([\d.] +)/))? Match_str[1]:
(Match_str = Ua_str.match (/rv: ([\d.] +)/))? Match_str[1]: 0;
Ie:indicate the really version of current IE browser.
Ie_tridents = {"trident/7.0": One, "trident/6.0": Ten, "trident/5.0": 9, "trident/4.0": 8};
Match IE8, IE11, Edge
Trident = (Match_str = Ua_str.match (/(trident\/[\d.) +|edge\/[\d.] +)/))? Match_str[1]: undefined;
Browser_chi_type = (Ie_tridents[trident] | | ie_aer_rv) > 0? "IE": undefined;
}else{
Judging Windows Edge Browser
MATCH_STR[1]: Return the browser and version number, such as: "edge/13.10586"
MATCH_STR[1]: Returns the version number, for example: "Edge"
To return to "edge", please change the "ie" on the downside to "edge". Note that the quotation marks and colons are entered in the English state.
Browser_chi_type = (Match_str = Ua_str.match (/edge\/([\d.] +)/)) ? "IE":
Determine Firefox browser
(Match_str = Ua_str.match (/firefox\/([\d.] +)/)) ? "Firefox":
Determine the Chrome browser
(Match_str = Ua_str.match (/chrome\/([\d.] +)/)) ? "Chrome":
Judging Opera browser
(Match_str = Ua_str.match (/opera. ( [\d.] +)/)) ? "Opera":
Judging Safari Browser
(Match_str = Ua_str.match (/version\/([\d.] +). *safari/))? "Safari": undefined;
}
Console.log ("Author:aerchi, Blog:http://blog.csdn.net/aerchi");
return browser type and version number
var vernum, Verstr;
Vernum = Trident && ie_tridents[trident]? Ie_tridents[trident]: match_str[1];
VERSTR = (getversion! = undefined)? Browser_chi_type+ "/" +VERNUM:BROWSER_CHI_TYPE;
return verstr;
}
Happy to be original, strictly forbidden to collect or use for personal website.
Reprint please specify the author and the original address
This address: http://blog.csdn.net/aerchi/article/details/51697592
Reprint--JS Depending on the browser's useagent to determine the type of browser