Loading

JS判断当前访问设备是手机/平板/电脑?

 JS判断当前访问设备是手机/平板/电脑?

一、程序代码 

	<script>
		var os = function () {
			var ua = navigator.userAgent,
				isWindowsPhone = /(?:Windows Phone)/.test(ua),
				isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
				isAndroid = /(?:Android)/.test(ua),
				isFireFox = /(?:Firefox)/.test(ua),
				isChrome = /(?:Chrome|CriOS)/.test(ua),
				isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox &&
					/(?:Tablet)/.test(ua)),
				isPhone = /(?:iPhone)/.test(ua) && !isTablet,
				isPc = !isPhone && !isAndroid && !isSymbian;
			return {
				isTablet: isTablet,
				isPhone: isPhone,
				isAndroid: isAndroid,
				isPc: isPc
			};
		}();
		console.log('os', os)
		if (os.isAndroid || os.isPhone) {
			// 手机
			window.location.href = "https://m.xxxx.com";

		} else if (os.isTablet) {
			// 平板
		} else if (os.isPc) {
			// 电脑
		}
	</script>

二、运行结果

posted @ 2022-04-13 02:56  Roc-xb  阅读(310)  评论(0编辑  收藏  举报

易微帮源码


易微帮官网