<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title></title>
<script>
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))) {
if (window.location.href.indexOf("?mobile") < 0) {
try {
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
var path = window.location.pathname;
var domain = window.location.host;
// 替换成对应的手机域名
window.location.href = "http://m.onestopweb.cn"+path+"?"+domain;
}
} catch (e) {}
}
}
</script>
</head>
<body>
<script>
document.write(window.location.pathname);//获取路径
document.write('<br>');
document.write(window.location.host);//获取域名
document.write('<br>');
document.write(document.domain);//获取域名
</script>
</body>
</html>
效果图:
本文介绍了一种通过JavaScript实现的网页适配方案,该方案能够检测用户是否使用移动设备访问,并将移动设备用户重定向到特定的移动版网站地址。此方法对于希望为移动用户提供更佳体验的网站开发者来说非常实用。
511

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



