简体   繁体   English

从移动网站转到完整网站?

[英]Go from mobile site to full site?

I have made a website with HTML and Javascript. 我用HTML和Javascript制作了一个网站。 When someone goes on the full site with an iPhone or iPod Touch it redirects them. 当某人使用iPhone或iPod Touch进入完整站点时,它将重定向他们。 The problem is that I have a link on my mobile one to go back to the full site which doesn't work because it just redirects them back to the mobile site. 问题是我在移动设备上有一个链接可以返回到整个站点,该链接不起作用,因为它只是将它们重定向回了移动站点。 Any help would be appreciated. 任何帮助,将不胜感激。

The javascript to redirect: 重定向的JavaScript:

    <script language=javascript>
        <!--
        if ((navigator.userAgent.match(/iPhone/i)) ||       (navigator.userAgent.match(/iPod/i))) {
            location.replace("Mobile version");
            }
            -->
    </script>

Add a cookie when the user selects to go to the full site. 当用户选择转到完整站点时,添加一个cookie。 Then in your redirect to mobile check to make sure that cookie doesn't exist. 然后,在您重定向到移动设备时,检查以确保不存在Cookie。

To set the cookie: 设置cookie:

var expire = new Date();
expire.setTime(expire.getTime()+(1*24*60*60*1000));
document.cookie = "nomobile=true; expires="+expire+"; path=/";

To read the cookie: 读取Cookie:

function getCookie(c_name) {
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++) {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name) {
            return unescape(y);
        }
    }
}
if (!getCookie("nomobile")) {
    //USE THIS AREA TO CHECK THE USER AGENT AND REDIRECT AS YOU CURRENTLY ARE
}

One simple fix would be to check if the referrer is your own website. 一种简单的解决方法是检查引荐来源网址是否是您自己的网站。 It your coming from your own site, then don't redirect to the mobile version. 它来自您自己的网站,请不要重定向到移动版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM