判断PC 电脑端跳转手机端JS教程 手机访问自动跳转JS

新建一个js 如 goto-m.js

function browserRedirect(url) {

var sUserAgent = navigator.userAgent.toLowerCase();

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 (bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM){

window.location.replace(url);

}

}

在网站<head>位置引入这个js

<script src=’https://wentong.org/goto-m.js’ language=’javascript’></script>
<script type=”text/javascript”>
browserRedirect(“https://m.wentong.org/”);//移动站URL
</script>

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:判断PC 电脑端跳转手机端JS教程 手机访问自动跳转JS