我正在使用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技能是相当新的,所以如果有人有更好的解决方案,我会全力支持。
发布于 2012-08-28 06:05:17
将会话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')https://stackoverflow.com/questions/12144775
复制相似问题