<script type= "Text/javascript" >
<!--//platform, device and operating system VAR system ={win:false,mac:false,xll:false};//detection Platform var p = Navigator.platform;//alert (p); SYSTEM.W in = P.indexof ("Win") = = 0;system.mac = P.indexof ("mac") = = = 0;system.x11 = (p = = "X11") | | (P.indexof ("Linux") = = 0);//Jump statement if (system.win| | system.mac| | SYSTEM.XLL) {//Turn to Background landing page document.write (');} Else{document.write (');} --></script>
<!--
if (navigator.userAgent.indexOf (' Ucbrowser ') >-1) {
alert (123);
}-->//-------
Many browsers use unified functionality, and the way they are implemented differs depending on the core of the browser. So sometimes we need to detect the browser.
A The problem lies
In the basic classroom, we adopt two kinds of schemes, one is direct supply, one is analysis. Both of these schemes are cumbersome, but relatively delicate, and in the actual use, it is not necessary.
Two Setup Code
Browser Detection
(function () {
Window.sys = {};
var ua = Navigator.userAgent.toLowerCase ();
var s;
if (/msie ([\d.] +)/). Test (UA)) {//To determine IE Browser
s = Ua.match (/msie ([\d.] +)/);
sys.ie = s[1];
}
if (/firefox\/([\d.] +)/). Test (UA)) {//to determine Firefox browser
s = Ua.match (/firefox\/([\d.] +)/);
Sys.firefox = s[1];
}
if (/chrome\/([\d.] +)/). Test (UA)) {// judge Google Chrome
s = Ua.match (/chrome\/([\d.] +)/);
Sys.chrome = s[1];
}
if (/opera.*version\/([\d.] +)/). Test (UA)) {// judge opera browser
s = Ua.match (/opera.*version\/([\d.] +)/);
Sys.opera = s[1];
}
if (/version\/([\d.] +). *safari/). Test (UA) {// judge Safari Browser
s = Ua.match (/version\/([\d.] +). *safari/);
Sys.safari = s[1];
}
alert (sys.ie);
})();
PS: The above notation contains a lot of duplicate code, we do a bit of compression.
Browser Detection
(function () {
Window.sys = {};
var ua = Navigator.userAgent.toLowerCase ();
var s;
(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.*version\/([\d.] +)/)) ? Sys.opera = S[1]:
(s = Ua.match (/version\/([\d.] +). *safari/))? Sys.safari = S[1]: 0;
})();
Computer Browser and Mobile browser