Javascript method for obtaining browser types and versions (js method for obtaining browser versions) _ basic knowledge

Source: Internet
Author: User
This article mainly introduces how to obtain the type and version of a browser using javascript (js to obtain the browser version). For more information, see The Code is as follows:


Function getExplorerInfo (){
Var explorer = window. navigator. userAgent. toLowerCase ();
// Ie
If (explorer. indexOf ("msie")> = 0 ){
Var ver = explorer. match (/msie ([\ d.] +)/) [1];
Return {type: "IE", version: ver };
}
// Firefox
Else if (explorer. indexOf ("firefox")> = 0 ){
Var ver = explorer. match (/firefox \/([\ d.] +)/) [1];
Return {type: "Firefox", version: ver };
}
// Chrome
Else if (explorer. indexOf ("chrome")> = 0 ){
Var ver = explorer. match (/chrome \/([\ d.] +)/) [1];
Return {type: "Chrome", version: ver };
}
// Opera
Else if (explorer. indexOf ("opera")> = 0 ){
Var ver = explorer. match (/opera. ([\ d.] +)/) [1];
Return {type: "Opera", version: ver };
}
// Safari
Else if (explorer. indexOf ("Safari")> = 0 ){
Var ver = explorer. match (/version \/([\ d.] +)/) [1];
Return {type: "Safari", version: ver };
}
}
Alert ("type:" + getExplorerInfo (). type + "\ nversion:" + getExplorerInfo (). version );

Related Article

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.