I am using this as my link in webpage.
<a class="btn btn-lg btn-orange" role="button" onclick="myFunction()">like me</a>
And this as my script.
function myFunction() {
$(function(){
window.location = "fb://profile/1456471431314551";
setTimeout(function () { window.location = "https://www.facebook.com/angelsatwork2015"; }, 25);
})
}
When I open in mobile both the browser fb page and the fb app open. Please help so that if the app opens it does not redirect to fb browser page. Also when I use this code on desktop two different browser pages open.
This is most likely the expected behavior for that code.
What you're doing when that button is clicked is immediately opening the URL
fb://profile/1456471431314551
. Assuming this is iOS, this causes the system to show an alert asking if you want the app to launch. However, as of iOS 9.2, this alert is non-blocking, which means other code continues to execute in the background. This is why, 25 milliseconds later, you're opening the URLhttps://www.facebook.com/angelsatwork2015
as a regular webpage.Unfortunately there is no good solution to this in the iOS 9.2+ world (thanks, Apple...). What we do at Branch.io is a combination of Universal Links (which launch the app when it is installed...most of the time) and redirections like the one you're trying for edge cases where Universal Links don't work. We set tracking cookies based on device UUID to know when we are safe to attempt launching the app, but in reality, this often means we have to redirect to the App Store if we aren't sure, just to avoid the behavior you're encountering.