当前位置:Gxlcms > JavaScript > 浏览器类型怎样通过js获取

浏览器类型怎样通过js获取

时间:2021-07-01 10:21:17 帮助过:4人阅读


<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
			function isWeChat() {
				var userAgent = navigator.userAgent.toLowerCase();
				if(userAgent.match(/MicroMessenger/i) == 'micromessenger') {
					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>



以上就是浏览器类型怎样通过js获取的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行