Heim  >  Artikel  >  Backend-Entwicklung  >  javascript - pc版跳m版ok,但m版点pc版链接不能停在pc版

javascript - pc版跳m版ok,但m版点pc版链接不能停在pc版

WBOY
WBOYOriginal
2016-06-06 20:13:09946Durchsuche

pc版跳m版ok,但m版点pc版链接不能停在pc版还是再跳到m版
以下是pc端代码在

<code>   <script type="text/javascript">
    if(window.localStorage){
        if(sessionStorage.getItem("isM")!="MOK"){
            var browser={  
                versions:function(){   
                       var u = navigator.userAgent, app = navigator.appVersion;   
                       return {
                            trident: u.indexOf("Trident") > -1,
                            presto: u.indexOf("Presto") > -1,
                            webKit: u.indexOf("AppleWebKit") > -1,
                            gecko: u.indexOf("Gecko") > -1 && u.indexOf("KHTML") == -1,
                            mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/),
                            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
                            android: u.indexOf("Android") > -1,
                            iPhone: u.indexOf("iPhone") > -1,
                            iPad: u.indexOf("iPad") > -1,
                            webApp: u.indexOf("Safari") == -1,
                            QQbrw: u.indexOf("MQQBrowser") > -1,
                            ucLowEnd: u.indexOf("UCWEB") > -1,
                            ucSpecial: u.indexOf("rv:1.2.3.4") > -1,
                            ucweb: u.indexOf("UCBrowser") > -1,
                            Symbian: u.indexOf("Symbian") > -1,
                            ucSB: u.indexOf("Firefox/1.") > -1                
                        }
                     }()  
            };
            if (screen == undefined || screen.width < 810) {
                if (browser.versions.mobile == true || browser.versions.iPhone == true || browser.versions.ucweb == true || browser.versions.android == true || browser.versions.Symbian == true) {
                    window.location.href = "m.htm";        
                }  
            };
        }else{sessionStorage.setItem("isM", "PCOK");}    
    }
    </script></code>

以下是m版head中代码

<code><script type="text/javascript">
if(window.localStorage){sessionStorage.setItem("isM", "MOK");}
</script>
</code>

求如何实现在m版点pc版链接时能浏览pc版?

回复内容:

pc版跳m版ok,但m版点pc版链接不能停在pc版还是再跳到m版
以下是pc端代码在

<code>   <script type="text/javascript">
    if(window.localStorage){
        if(sessionStorage.getItem("isM")!="MOK"){
            var browser={  
                versions:function(){   
                       var u = navigator.userAgent, app = navigator.appVersion;   
                       return {
                            trident: u.indexOf("Trident") > -1,
                            presto: u.indexOf("Presto") > -1,
                            webKit: u.indexOf("AppleWebKit") > -1,
                            gecko: u.indexOf("Gecko") > -1 && u.indexOf("KHTML") == -1,
                            mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/),
                            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
                            android: u.indexOf("Android") > -1,
                            iPhone: u.indexOf("iPhone") > -1,
                            iPad: u.indexOf("iPad") > -1,
                            webApp: u.indexOf("Safari") == -1,
                            QQbrw: u.indexOf("MQQBrowser") > -1,
                            ucLowEnd: u.indexOf("UCWEB") > -1,
                            ucSpecial: u.indexOf("rv:1.2.3.4") > -1,
                            ucweb: u.indexOf("UCBrowser") > -1,
                            Symbian: u.indexOf("Symbian") > -1,
                            ucSB: u.indexOf("Firefox/1.") > -1                
                        }
                     }()  
            };
            if (screen == undefined || screen.width < 810) {
                if (browser.versions.mobile == true || browser.versions.iPhone == true || browser.versions.ucweb == true || browser.versions.android == true || browser.versions.Symbian == true) {
                    window.location.href = "m.htm";        
                }  
            };
        }else{sessionStorage.setItem("isM", "PCOK");}    
    }
    </script></code>

以下是m版head中代码

<code><script type="text/javascript">
if(window.localStorage){sessionStorage.setItem("isM", "MOK");}
</script>
</code>

求如何实现在m版点pc版链接时能浏览pc版?

可以在跳转的时候给移动或者pc站传一个特定参数,当然如果你是想每个页面都不会跳转过去,那么你可以在获取这个参数之后,把他传入cookie中,然后用js识别判断。
还有就是利用后端技术协助也可以的。
不知道能否帮助你

pc版不要判断是否移动端不就可以了

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn