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

编程入门 行业动态 更新时间:2024-10-23 19:29:09
本文介绍了带有完整站点链接的移动站点重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm using the javascript version from detectmobilebrowsers/ 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 = "thefullsiteURL"} else { function (a, b) { if (//mobile direction stuff from detectmobilebrowsers })(navigator.userAgent || navigator.vendor || window.opera, 'thefullsiteURL/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='mysite?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, 'thefullsiteURL/mobile/index.html')

更多推荐

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

本文发布于:2023-11-01 17:52:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550004.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:站点   重定向   完整   链接

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!