gpt4 book ai didi

javascript - 带有完整站点链接的移动站点重定向

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:27:01 24 4
gpt4 key购买 nike

我正在使用来自 http://detectmobilebrowsers.com/ 的 javascript 版本重定向到移动网站。唯一的问题是我有一个链接可以转到完整站点,以防用户想要/需要去那里。

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

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

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

最佳答案

在您的完整站点链接中设置 session cookie 和查询字符串值。然后,让您的移动检测代码首先检查 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')

关于javascript - 带有完整站点链接的移动站点重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12144775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com