2

I have this code to open my facebook page from my website link. But when browsing my page on mobile browser it open facebook link in browser too but I'd like to open the facebook page in app if installed. Here is my code

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

Lusidjudjeto
  • 21
  • 1
  • 1
  • 6
  • Possible duplicate of [Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?](https://stackoverflow.com/questions/1108693/is-it-possible-to-register-a-httpdomain-based-url-scheme-for-iphone-apps-like) – Sinan Samet Dec 09 '17 at 15:20

2 Answers2

0

replace //facebook.com with fb://

<a href="fb://myfacepage/" target="_blank" rel="alternate"><img src="images/facebook-logo.png" alt="" /></a></p>
Michael Andorfer
  • 1,660
  • 5
  • 25
  • 45
  • 4
    ... but keep in mind that most desktop browsers will most likely have no idea how to handle that. And on mobile devices that do not have the Facebook app installed, this would fail as well of course. I don’t think that should be implemented without any check first. – CBroe Dec 11 '17 at 08:26
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>