移动站点重定向与完整的站点链接

mobile site redirect with full site link

本文关键字:站点 链接 重定向 移动      更新时间:2023-09-26

我使用的是http://detectmobilebrowsers.com/重定向到移动站点。唯一的问题是,我有一个链接到完整的网站,在用户想要/需要去那里的机会。

然而,当你点击链接从移动设备上查看完整的网站时,它会重新启动重定向,并将其踢回移动版本,而不是完整的网站。

我在做一些搜索,想知道是否有可能破解它,使其使用

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技能相当新,所以如果有人有更优雅的解决方案,我完全支持。

在完整的站点链接中设置会话cookie和querystring值。然后,让您的移动检测代码首先检查cookie值,其次检查查询字符串,最后检查用户代理移动检测。

因此,您的完整站点链接应该与查询字符串触发器类似:

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

然后在你的手机检测:

;(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')