location.pathname(location 对象的 pathname 属性)用于设置或取得当前 URL 的路径部分
<script type="text/javascript">
var path = location.pathname;
alert(path);
</script>
效果图:
前提是手机和PC站都同一个数据库,更新的路径都是相同的,只是域名的不同。一个是www,另一个是m。
function browserRedirect() {
var hz=location.pathname;
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
window.location.href="http://m.onestopweb.cn"+hz+"#www";
} else {
}
}
browserRedirect();
为了防止有些无法跳转到手机端,故下面加上百度提供的跳转代码。
<script src='http://siteapp.baidu.com/static/webappservice/uaredirect.js' type='text/javascript'></script>
<script type='text/javascript'>uaredirect('http://m.onestopweb.cn/?www.onestopweb.cn');</script>
标签:windows,sUserAgent,JS,pathname,location,跳转,var,match,页面 From: https://blog.51cto.com/u_16171388/6557264