Javascript code for judging the browser type and version number _ javascript tips-js tutorial

Source: Internet
Author: User
I analyzed it today and finally found the reason. the browser written in the js file of the old version has an exception, so the insertion point remains in the header. phpnew blog built-in discuz ubb editor. The editor function is inserted at the cursor, which is inaccurate on ie11.
Today, I analyzed the cause and finally found the cause. The browser written in the js file of the old version is abnormal, so the insertion point is always in the header. I fixed it today.

Provides a js function. returns an array.

The Code is as follows:


Function sys_userAgent (){
Var userAgent = navigator. userAgent,
RMsie =/(msie \ s | trident. * rv :) ([\ w.] + )/,
RFirefox =/(firefox) \/([\ w.] + )/,
ROpera =/(opera). + version \/([\ w.] + )/,
RChrome =/(chrome) \/([\ w.] + )/,
RSafari =/version \/([\ w.] +). * (safari )/;
Var browser, version, ua;
Ua = userAgent. toLowerCase ();

Var match = rMsie.exe c (ua );
If (match! = Null ){
Return {browser: "ie", version: match [2] | "0 "};
}

If (!! Window. ActiveXObject | "ActiveXObject" in window ){
Return {browser: "ie", version: "0 "};
}

Var match = rFirefox.exe c (ua );
If (match! = Null ){
Return {browser: "firefox", version: match [2] | "0 "};
}

Var match = rOpera.exe c (ua );
If (match! = Null ){
Return {browser: "opera", version: match [2] | "0 "};
}

Var match = rChrome.exe c (ua );
If (match! = Null ){
Return {browser: "chrome", version: match [2] | "0 "};
}

Var match = rSafari.exe c (ua );
If (match! = Null ){
Return {browser: "safari", version: match [1] | "0 "};
}

If (match! = Null ){
Return {browser: "", version: "0 "};
}
}

I hope to help you.
The edited content of the editor also contains the problem that the attachment flash loading often fails to be fixed. Press enter to solve the problem.

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.