有没有办法执行与Facebook的移动侦测完全匹配的移动侦测? [英] Is there a way to perform a mobile detect that EXACTLY matches Facebook's mobile detect?

查看:92
本文介绍了有没有办法执行与Facebook的移动侦测完全匹配的移动侦测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个混合的Facebook应用:桌面用户将被定向到页面标签,而移动用户将被定向到移动网络应用.

I'm building a hybrid Facebook app: desktop users will be directed to a Page Tab, while mobile users will be directed to a Mobile Web App.

我需要找出一种快速,准确的方法,以检测用户的设备并执行适当的重定向-理想情况下,这不太复杂.能做到吗?

I need to figure out a fast, accurate way to detect the user's device and perform the appropriate redirect – ideally something not too complex. Can it be done?

推荐答案

...是的!完全可以做到.

…Yes! It can absolutely be done.

Facebook会自动将尝试访问Canvas应用程序(apps.facebook.com/your_app)的移动用户重定向到其等效的移动Web应用程序.

Facebook automatically redirects mobile users attempting to access a Canvas App (apps.facebook.com/your_app) to its Mobile Web App equivalent.

因此,只需将服务器端重定向设置为apps.facebook.com/your_app,并设置从Canvas应用到页面标签的客户端重定向.

So, just set up a server-side redirect to apps.facebook.com/your_app, and set up a client-side redirect from the Canvas App to the Page Tab.

Facebook会将移动用户重定向到您的移动Web应用;桌面用户将登陆您的Canvas应用,该应用将立即将他们重定向到您的页面"标签.

Facebook will redirect mobile users to your Mobile Web App; desktop users will land on your Canvas App, which will immediately redirect them to your Page Tab.

在PHP中,服务器端重定向如下所示:

The server-side redirect looks like this, in PHP:

<?php
header('Location: http://apps.facebook.com/your_app', TRUE, 302);
exit;

在JavaScript中,客户端重定向如下所示:

The client-side redirect looks like this, in JavaScript:

<script type="text/javascript">window.top.location.href = "http://yoururl.com/desktop/";</script>

这是一个可靠的解决方案,比尝试匹配用户代理要好得多.您的用户代理列表可能与Facebook不同.确实,Facebook与它执行移动重定向的方式非常不一致.

This is a reliable solution, much better than trying to match user agents. Your list of user agents might be different from Facebook's; and indeed, Facebook is very inconsistent with how it performs mobile redirects.

这篇关于有没有办法执行与Facebook的移动侦测完全匹配的移动侦测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆