JS get browser type and version information

Source: Internet
Author: User
Tags microsoft edge

Bro () {
Let Broname = ' runing '
Let Strstart = 0
Let Strstop = 0
Let temp = "
Let useragent = window.navigator.userAgent//A string containing all or part of the following properties: Appcodename,appname,appversion,language,platform
FireFox
if (Useragent.indexof (' Firefox ')!==-1) {
Strstart = Useragent.indexof (' Firefox ')
temp = useragent.substring (Strstart)
Broname = Temp.replace ('/', ' version number ')
}
Edge
if (Useragent.indexof (' Edge ')!==-1) {
/* Broname = ' Edge browser '; */
Strstart = Useragent.indexof (' Edge ')
temp = useragent.substring (Strstart)
Broname = Temp.replace ('/', ' version number ')
}
IE browser
if (Useragent.match (/msie ([\d.] +)/)) {
/* broname = ' ie browser '; */
Let S = Useragent.match (/msie ([\d.] +)/)
Let res = ' IE ' + s[1]
Broname = res + res.replace (/[^0-9.) /ig, ")
}
360 speed mode can differentiate between 360 secure browser and 360 Speed browser
if (Useragent.indexof (' WOW ')!==-1 && useragent.indexof (' NET ') < 0 && useragent.indexof (' Firefox ') & Lt 0) {
if (navigator.javaenabled ()) {
Broname = ' 360 secure browser-speed mode '
} else {
Broname = ' 360 speed browser-speed mode '
}
}
360 compatible
if (Useragent.indexof (' WOW ')!==-1 && useragent.indexof (' NET ')!==-1 && useragent.indexof (' MSIE ')!==- 1 && useragent.indexof (' RV ') < 0) {
Broname = ' 360 compatibility mode '
}
Chrome browser
if (Useragent.match (/chrome\/([\d.] +)/)) {
/* Broname = ' Chrome browser '; */
Strstart = Useragent.indexof (' Chrome ')
Strstop = Useragent.indexof (' Safari ')
temp = useragent.substring (Strstart, Strstop)
Broname = Temp.replace ('/', ' version number ')
}
Safari
if (Useragent.match (/version\/([\d.] +). *safari/)) {
Strstop = Useragent.indexof (' Safari ')
temp = useragent.substring (strstop)
Broname = Temp.replace ('/', ' version number ')
}
Opera
if (Useragent.match (/opera) ( [\d.] +)/)) {
Strstop = Useragent.indexof (' Opera ')
temp = useragent.substring (strstop)
Broname = Temp.replace ('/', ' version number ')
}
Return Broname
}

Reference documents: https://www.cnblogs.com/muscleape/p/6897356.html
JavaScript gets information such as browser version * * Different browser versions may differ, please test your environment when using * * Test each browser version Ie:11.953.14393.0edge:microsoft Edge 38.14393.0.0; Microsoft edgehtml 14.14393chrome:57.0.2987.133 (64-bit) firefox:52.0.1 (32-bit) 360 Speed Browser: Version number: 8.7.0.306; kernel version number : 50.0.2661.102360 Security Browser: Version number: 8.1.1.400; kernel version number: 45.0.2454.101 Program source code <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

  

JS get browser type and version information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.