Home  >  Article  >  Web Front-end  >  js code to determine browser type and version number_javascript skills

js code to determine browser type and version number_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:48:541165browse

phpnew blog has a built-in discuz ubb type editor. The editor function includes inserting at the cursor, but it has always been inaccurate on ie11.
After analyzing it today, I finally found the reason. Browse the old version of the js file written There is an abnormality in the processor's judgment, so the insertion point is always at the head. It will be fixed today.

Provide a js function. Return an array.

Copy code The code is as follows:

function sys_userAgent(){
var userAgent = navigator .userAgent, 
rMsie = /(msies|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.exec(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.exec(ua);
if (match != null) {
return { browser : "firefox", version : match[2] || "0" };

var match = rOpera.exec(ua);
if (match != null) {
return { browser : "opera", version : match[2] || "0" };
}  

var match = rChrome.exec(ua);
if (match != null) {
return { browser : "chrome", version : match[2] || "0" };
}  

var match = rSafari.exec(ua);
if (match != null) {
return { browser : "safari", version : match[1] || "0" };
}  

if (match != null) {
return { browser : "", version : "0" };
}
}

Hope it is helpful to everyone.
The content modified by the editor also fixes the problem of frequent failure to load attachment flash and solves the carriage return problem.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn