m端访问pc端 让跳到对应m端

function isMobile(){
if( navigator.userAgent.match(/Android/i)|| navigator.userAgent.match(/webOS/i)|| navigator.userAgent.match(/iPhone/i)|| navigator.userAgent.match(/iPad/i)|| navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i))
{
return true;
}else{
return false;
}
}
console.log(isMobile());

if(isMobile()){
var str = window.location.href;
var href = str.replace("www","m");
window.location=href;
}

posted @ 2021-04-02 10:14  宋先生日记  阅读(158)  评论(0编辑  收藏  举报