其他分享
首页 > 其他分享> > js双端互跳

js双端互跳

作者:互联网

pc跳移动端
//方案一
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))){
    try{
        if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
            //触屏手机版地址
            var url = window.location.href.replace("http://www","http://m");
            window.location.href = url;
        }else if(/iPad/i.test(navigator.userAgent)){
            //pad版地址
            var url = window.location.href.replace("http://www","http://m");
            window.location.href = url;
        }else{
            //普通手机版地址
            var url = window.location.href.replace("http://www","http://m");
            window.location.href = url;
        }
    }
    catch(e){
    }
}


//方案二
    if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
       window.location.href = "移动端地址";
    }
    
//移动端跳pc    
 var isOnPc=!(/Android|webOS|iPhone|iPod|BlackBerry|BB10|Symbian|Nokia|UCWEB|IEMobile|opera mini/i.test(navigator.userAgent));
 
 //上面这个表示不是移动端
 //下面这句话的意思是不是移动端的时候跳转到相应的地址
  isOnPc && (location.href="地址");

标签:互跳,双端,js,window,href,location,test,userAgent,navigator
来源: https://blog.csdn.net/qq_42286878/article/details/122147825