//腾讯网判断 手机、IPad、PC的JS代码
<script type="text/javascript" language="javascript">
window.onload = function init() {
if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))) {
try {
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
alert('Mobile Web');
} else if (/iPad/i.test(navigator.userAgent)) {
alert('ipad');
} else {
alert('else');
}
} catch (e) { }
}
else {
alert('PC');
}
}
</script>
本文提供了一段用于判断用户设备类型的JavaScript代码,通过解析navigator.userAgent来区分移动设备(包括iPhone、iPad、Android等)、普通手机和其他PC设备。
1万+

被折叠的 条评论
为什么被折叠?



