The lowercase information of the UserAgent property of the Navigator object is obtained first, and then the assignment is evaluated according to the regular expression.
var Sys = {};var ua = Navigator.userAgent.toLowerCase (); var s;var scan; (s = Ua.match (/msie ([\d.] +)/)) ? sys.ie = S[1]: (s = Ua.match (/firefox\/([\d.] +)/)) ? Sys.firefox = S[1]: (s = Ua.match (/chrome\/([\d.] +)/)) ? Sys.chrome = S[1]: (s = Ua.match (/opera. ( [\d.] +)/)) ? Sys.opera = S[1]: (s = Ua.match (/version\/([\d.] +). *safari/))? Sys.safari = s[1]: 0;//test if (sys.ie) {scan = "ie kernel you are using" + sys.ie + "browser";} if (sys.firefox) {scan = "You are using the Firefox kernel" + sys.firefox + "browser";} if (sys.chrome) {scan = "You are using the chrome kernel" + sys.chrome + "browser";} if (sys.opera) {scan = "You are using the Opera kernel" + Sys.opera + "browser";} if (Sys.safari) {scan = "You are using the Safari kernel" + Sys.safari + "browser";} Alert (scan)
Itmyhome
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
JS Check browser type and version