带有完整站点链接的移动站点重定向 [英] mobile site redirect with full site link

查看:55
本文介绍了带有完整站点链接的移动站点重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 http://detectmobilebrowsers.com/中的javascript版本重定向到移动网站.唯一的是,我有一个链接,可以在用户希望/需要访问整个站点的情况下访问整个站点.

I'm using the javascript version from http://detectmobilebrowsers.com/ to redirect to a mobile site. The only thing is that I have a link to go to the full site in the off chance that users want/need to go there.

但是,当您单击链接从移动设备查看完整的网站时,它会重新选择重定向并将其踢回到移动版本而不是完整的网站.

However, when you click on the link to view the full site from the mobile, it picks back up on the redirection and kicks it back to the mobile version and not to the full site.

我正在做一些搜索,想知道是否有可能对其进行黑客入侵,以便其使用

I was doing some searching and was wondering if it could be possible to hack it so that it uses

window.location.href.indexOf

或类似性质的东西

if(window.location.href.indexOf("mobile/index.html") > -1)
{window.location = "http://thefullsiteURL.com"}
else { function (a, b) {
if (//mobile direction stuff from detectmobilebrowsers.com
})(navigator.userAgent || navigator.vendor || window.opera,
'http://thefullsiteURL.com/mobile/index.html')};

请记住,这是我拼凑而成的,并且我的JS技能是相当新的,因此,如果有人有更优雅的解决方案,我将全力以赴.

Keep in mid that this is something that I pieced together and my JS skills are fairly new, so if any one has a more elegant solution I am all for it.

推荐答案

在完整的网站链接中结合sessionstring设置会话cookie.然后,让您的移动设备检测代码首先检查Cookie值,然后检查查询字符串,最后检查用户代理移动设备检测.

Set a session cookie in conjunction with a querystring value in your full site link. Then, have your mobile detect code check first for the cookie value, second for the query string, and last for user agent mobile detect.

因此,完整的网站链接应类似于查询字符串触发器:

So your full site link should be something like with the query string trigger:

<a href='http://mysite.com?fullsite=true'>Link to full site</a>

然后在您的手机中检测:

And then in your mobile detect:

;(function(a,b) {

    if (document.cookie.indexOf('fullsite') > -1) {
        return; // skip redirect
    }
    if (location.search.indexOf('fullsite') > -1) {
        document.cookie = 'fullsite=true; path=/;'
        return; // skip redirect
    } 
    if (/mobile regex conditional goes here/) {
        window.location = b;
    }
})(navigator.userAgent || navigator.vendor || window.opera, 'http://thefullsiteURL.com/mobile/index.html')

这篇关于带有完整站点链接的移动站点重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆