js判断浏览器的环境(pc端,移动端,还是微信浏览器)

window.navigator.userAgent用来区分设备和浏览器

 <!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>判断浏览器的环境</title>
</head>

<body>


</body>
<script>
	if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
		alert(navigator.userAgent+'现在移动端打开的')
	} else {
		alert(navigator.userAgent+'现在是pc端打开的')
	}

	var wx = (function () { return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1 })();
	if (wx) {
		alert(navigator.userAgent+"是微信");
	} else {
		alert(navigator.userAgent+"不是微信");
	}
	 alert(navigator.userAgent.toLowerCase());


</script>

</html>
posted @ 2018-10-18 14:46  李美玲  阅读(2686)  评论(0编辑  收藏  举报