When using facebook deep URL to open app, both app and webpage open together

我们两清 提交于 2019-12-25 07:15:37

问题


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.


回答1:


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 URL https://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.



来源:https://stackoverflow.com/questions/37946195/when-using-facebook-deep-url-to-open-app-both-app-and-webpage-open-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!