js判断手机访问PC端跳转到手机站

时间:2023-03-08 15:48:12

<script type="text/javascript">
(function() {

//得到域名后缀
var path = location.pathname.split('/')
path = path.pop();

var ua = navigator.userAgent.toLowerCase();
var bIsIpad = ua.match(/ipad/i) == "ipad";
var bIsIphoneOs = ua.match(/iphone os/i) == "iphone os";
var bIsAndroid = ua.match(/android/i) == "android";
var bIsWM = ua.match(/windows mobile/i) == "windows mobile";
if (bIsIphoneOs || bIsAndroid || bIsWM) {
window.location.href = "http://m.51jinsha.net/"+path;   //跳转到二级页面
}
})();
</script>