Home > Web Front-end > JS Tutorial > How to get the browser type through js

How to get the browser type through js

一个新手
Release: 2017-09-07 09:35:38
Original
1353 people have browsed it


<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
			function isWeChat() {
				var userAgent = navigator.userAgent.toLowerCase();
				if(userAgent.match(/MicroMessenger/i) == &#39;micromessenger&#39;) {
					return true;
				} else {
					return false;
				}
			}

			function browser() {
				//取得浏览器的userAgent字符串
				var userAgent = navigator.userAgent;
				var isIE = window.ActiveXObject != undefined && userAgent.indexOf("MSIE") > -1;
				var isFirefox = userAgent.indexOf("Firefox") > -1;
				var isOpera = window.opr != undefined;
				var isChrome = userAgent.indexOf("Chrome") && window.chrome;
				var isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Version") > -1;
				if(isIE) {
					return "IE";
				} else if(isFirefox) {
					return "Firefox";
				} else if(isOpera) {
					return "Opera";
				} else if(isChrome) {
					return "Chrome";
				} else if(isSafari) {
					return "Safari";
				} else {
					return "Unkown";
				}
			}

			window.onload = function() {
				var brow = browser();
				if("Chrome" == brow) {
					alert("Chrome");
				}
				if("Firefox" == brow) {
					alert("Firefox");
				}
				if("Opera" == brow) {
					alert("Opera");
				}
				if("Safari" == brow) {
					alert("Safari");
				}
				if("IE" == brow) {
					alert("IE");
				}
			}
		</script>
	</head>
	<body>
	</body>
</html>
Copy after login



The above is the detailed content of How to get the browser type through js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template