首页 > 解决问题 > 正文

Pc站页面跳转到对应手机页面
2022-06-02 17:26:28   来源:   评论:0 点击:

Pc站页面跳转到对应手机页面var url = window location pathname;var wapurl="http: m baidu com"+urlif( AppleWebKit *Mobile i test

Pc站页面跳转到对应手机页面

var url = window.location.pathname;

var wapurl="http://m.baidu.com"+url

 

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)){

                 window.location.href=wapurl;

            }else{

                window.location.href=wapurl;

            }

        }catch(e){}

    }

}

手机站页面跳转到Pc对应页面

var url = window.location.pathname;

var pcurl="http://www.baidu.com"+url

 

if(/AppleWebKit.*Mobile/i.test(navigator.userAgent)==false || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))==false){

    if(window.location.href.indexOf("?mobile")<0){

        try{

            if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)==false){

                 window.location.href=pcurl;

            }

 

        }catch(e){}

    }

}

相关热词搜索:

上一篇:第一页
下一篇:泛解析大量域名的情况下 将不带www的域名,301到指定的域名

分享到: 收藏