如何从网站链接打开Facebook应用程序

时间:2017-12-09 11:13:25

标签: javascript jquery html facebook facebook-graph-api

我有这个代码从我的网站链接打开我的Facebook页面。 但是当在移动浏览器上浏览我的页面时,它也会在浏览器中打开facebook链接,但是我想在应用程序中打开facebook页面(如果已安装)。 这是我的代码

<script type="text/javascript"> $(function () { $("select#CountryID").change(function (evt) { if ($("select#CountryID").val() != "-1") { $.ajax({ url: "/Home/GetStates", type: 'POST', data: { CountryID: $("select#CountryID").val() }, success: function (response) { $("#stateID").empty(); $("#stateID").view(response); }, error: function (xhr) { alert("Something seems Wrong"); } }); } }); }); </script>

2 个答案:

答案 0 :(得分:1)

//facebook.com替换为fb://

<a href="fb://myfacepage/" target="_blank" rel="alternate"><img src="images/facebook-logo.png" alt="" /></a></p>

答案 1 :(得分:0)

<?php
$iphone = strpos($_SERVER['HTTP_USER_AGENT'], "iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'], "Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'], "webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'], "BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'], "iPod");
//check if is a mobile
if ($iphone || $android || $palmpre || $ipod || $berry == true) {
$device = 'mobile';
}
//all others
else {
 $device = 'desktop';
}
?>

<html>
<ahref="<?php echo ($device=='mobile')?'fb://':'https://www.facebook.com/'; ?>zuck">Facebook</a>
</html>