Home > Web Front-end > JS Tutorial > js determines browser type and device (mobile page development)_javascript skills

js determines browser type and device (mobile page development)_javascript skills

WBOY
Release: 2016-05-16 15:48:19
Original
1148 people have browsed it

The following mainly uses javascript code to determine the browser type and device accessing the web page. It supports all browsers on mobile phones. The specific code is as follows.

<!DOCTYPE html>
<html>
<head>
<title>JS判断是什么设备是什么浏览器-www.jb51.net</title>
<meta charset="utf-8">
<meta name="apple-touch-fullscreen" content="YES" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="format-detection" content="telephone=no"/>

</head>
<body>
<div id="divid">
</div>
<script type="text/javascript">
var os = function() {
var ua = navigator.userAgent,
isQB = /(&#63;:MQQBrowser|QQ)/.test(ua), 
isWindowsPhone = /(&#63;:Windows Phone)/.test(ua),
isSymbian = /(&#63;:SymbianOS)/.test(ua) || isWindowsPhone, 
isAndroid = /(&#63;:Android)/.test(ua), 
isFireFox = /(&#63;:Firefox)/.test(ua), 
isChrome = /(&#63;:Chrome|CriOS)/.test(ua),
isIpad = /(&#63;:iPad|PlayBook)/.test(ua), 
isTablet = /(&#63;:iPad|PlayBook)/.test(ua)||(isFireFox && /(&#63;:Tablet)/.test(ua)),
isSafari = /(&#63;:Safari)/.test(ua),
isPhone = /(&#63;:iPhone)/.test(ua) && !isTablet,
isOpen= /(&#63;:Opera Mini)/.test(ua),
isUC = /(&#63;:UCWEB|UCBrowser)/.test(ua),
isPc = !isPhone && !isAndroid && !isSymbian;
return {
isQB: isQB,
isTablet: isTablet,
isPhone: isPhone,
isAndroid : isAndroid,
isPc : isPc,
isOpen : isOpen,
isUC: isUC,
isIpad : isIpad
};
}();
var html=[];
html[html.length]='是QQ浏览器:'+os.isQB+"<br/>";
html[html.length]='是Tablet:'+os.isTablet+"<br/>";
html[html.length]='是Phone:'+os.isPhone+"<br/>";
html[html.length]='是Android:'+os.isAndroid+"<br/>";
html[html.length]='是电脑:'+os.isPc+"<br/>";
html[html.length]='是Opera浏览器:'+os.isOpen+"<br/>";
html[html.length]='是UC浏览器:'+os.isUC+"<br/>";
html[html.length]='是Ipad:'+os.isIpad+"<br/>";
document.getElementById("divid").innerHTML=html.join("");
</script>
</body>
</html>
Copy after login

The above is the entire content of the javascript code to determine what device and what browser type (mobile page development). I hope you like it.

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template