通过ua检测浏览页面的设备是phone还是tablet

通过ua检测浏览页面的设备是phone还是tablet


function isPhone(ua) {
	var isMobile = /Mobile(\/|\s)/.test(ua);

	// Either:
	// - iOS but not iPad
	// - Android 2
	// - Android with "Mobile" in the UA

	return /(iPhone|iPod)/.test(ua) ||
			  (!/(Silk)/.test(ua) && (/(Android)/.test(ua) && (/(Android 2)/.test(ua) || isMobile))) ||
			  (/(BlackBerry|BB)/.test(ua) && isMobile) ||
			  /(Windows Phone)/.test(ua);
}

function isTablet(ua) {
	return !isPhone(ua) && (/iPad/.test(ua) || /Android/.test(ua) || /(RIM Tablet OS)/.test(ua) ||
		(/MSIE 10/.test(ua) && /; Touch/.test(ua)));
}

猜你喜欢

转载自sanshizi.iteye.com/blog/1881188