查看完整网站,而非 iPhone 上的移动版本
我有一个脚本可以检测您是否是 iPhone 用户并重定向到对 iPhone 更友好的页面。
<script type="text/javascript">
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
{
location.replace("http://domain.com/iphone/");
}
</script>
这很好用,但有一个问题。按照惯例,为用户提供查看完整网页的能力。但是,如果我链接到根目录,显然重定向会将它们发送到移动版本!
有关如何包含的任何想法,如果单击 /iphone/
中的链接,他们可以转到 /
并留在那里。
I have a script that detects whether you're an iPhone user or not and redirects to a more iPhone friendly page.
<script type="text/javascript">
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
{
location.replace("http://domain.com/iphone/");
}
</script>
This works great but has one problem. It is convention to offer the user the ability to view the full web page. However, if I link to the root, obviously the redirect is going to send them to the mobile version!
Any ideas on how to include if click on the link from /iphone/
, they can go to /
and stay there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当用户到达时,确定他们的浏览器类型 - 移动浏览器或完整浏览器 - 并使用该值设置 cookie。使用此 cookie 值来决定要显示的站点版本。正如您所提到的,向移动用户提供一个指向“完整”网站的链接,但如果他们单击它,请运行一个快速脚本将 cookie 更新为“完整”值,然后将他们重定向到完整网站。他们的 cookie 现在已针对整个网站进行设置,因此他们不会被弹回到移动网站。
现在,如果 cookie 是一个问题,您可以使用 PHP 之类的东西来设置会话值以维护会话的完整/移动状态,但这可能超出了原始问题的范围。
When the user arrives, determine their browser type - mobile or full - and set a cookie with this value. Use this cookie value to decide what version of the site to display. AS you mention, offer a link to the "full" site to the mobile users, but if they click it, run a quick script to update the cookie to the "full" value and then redirect them to the full site. Their cookie is now set for the full site, so they won't get bounced back to the mobile site.
Now, if cookie are a problem, you could use something like PHP to set a session values to maintain the full/mobile status of the session, but that's probably getting beyond the scope of the original question.
查询字符串是要走的路(正如其他人上面所说的那样)。看看 Facebook,如果您点击移动网站上的“完整网站”链接,它会重定向到 www.facebook.com/login.php?m2w - m2w 可能是 MobileToWeb,这将阻止网站将用户重定向到移动网站。
The Query String is the way to go ( as the others have said above). Looking at Facebook, if you click on the 'full site' link on the mobile site, it redirects to www.facebook.com/login.php?m2w - the m2w is probably MobileToWeb and this will prevent the site redirecting the user to the mobile site.