jq判断是否在移动端打开

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
	</head>
	<body>
		<script type="text/javascript">
			$(function(){
				if(navigator.userAgent.match(/mobile/i)) {
				//navigator.userAgent浏览器用于 HTTP 请求的用户代理头的值
					top.location='http://m.baidu.com/';
					//如果条件成立跳转百度
				}else{
					document.write('访问不是移动端')
				}
			});
		</script>
	</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_44348028/article/details/107921076