Js determines the browser type and version example for running jsp pages _ javascript tips-js tutorial

Source: Internet
Author: User
I made a business to judge the browser type and version number, and recorded the relevant js code. I personally feel pretty good, you can refer to the following two days to make a business that judges the browser type and version number, and record the relevant js Code:

The Code is as follows:


Function allinfo (){

Var ua = navigator. userAgent;
Ua = ua. toLowerCase ();
Var match =/(webkit) [\/] ([\ w.] +)/. exec (ua) |
/(Opera )(? :. * Version )? [\/] ([\ W.] +)/. exec (ua) |
/(Msie) ([\ w.] +)/. exec (ua) |
! /Compatible/. test (ua) &/(mozilla )(? :.*? Rv :( [\ w.] + ))? /. Exec (ua) | [];

// If you need to obtain the browser version: match [2]

Switch (match [1]) {
Case "msie": // ie
If (parseInt (match [2]) === 6) {// ie6
Alert ("ie6 ");
Alert ("IE7.0 and earlier browsers are not supported currently. Please upgrade your browser version! ");
// Document. getElementById ("hid"). style. display = "none ";
// Document. getElementById ("show"). style. display = "block ";
// Document. getElementById ("nosee_ B"). style. display = "none ";
}
Else if (parseInt (match [2]) === 7) {// ie7
Alert ("ie7 ");
// Document. getElementById ("hid"). style. display = "none ";
// Document. getElementById ("show"). style. display = "block ";
}
Else if (parseInt (match [2]) === 8) {// ie8
Alert ("ie8 ");
}
Else if (parseInt (match [2]) === 9 ){
Alert ("ie9 ");
// Document. getElementById ("hid"). style. display = "none ";
}
Break;
Case "webkit": // safari or chrome
// Alert ("safari or chrome ");
// Document. getElementById ("middle"). style. display = "none ";
Break;
Case "opera": // opera
Alert ("opera ");
Break;
Case "mozilla": // Firefox
Alert ("Firefox ");
// Document. getElementById ("hid"). style. display = "none ";
Break;
Default:
Break;
}
}

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.