Suppress Safari can't open the page because the address is invalid? custom app launch

纵饮孤独 提交于 2019-12-04 08:46:10

问题


I'm launching a custom app from a web browser on the iphone.

If the app is not installed I am redirecting to a web page on the website.

If it is installed it goes to a specific page on the app

This all works as expected except for about 1/2 a second safari displays a modal window saying the following

Cannot Open Page Safari cannot open the page because the address is invalid.

I know the address is invalid and I would like to know if its possible to suppress the error message in safari.

Thanks


回答1:


I did find a solution that worked for this. I had it working with a setTimeout of 25ms. But for some reason on a nexus 5 I needed to drop it down to 5ms.

i ended up using the following:

    function goToApp(appLocation, fallbackLocation) {

        setTimeout(function() {
            window.location = fallbackLocation;
             }, 5);
       window.location = "nativeappURL://" + appLocation;
    }

    function goToWeb(baseurl, webLocation) {
        window.location =baseurl + "/"+ webLocation;
    }
</script>

Then I just have two buttons that have an

 onclick="goToApp('appDestination', 'location')"

and

 onclick="goToWeb('webDestination', 'location')"


来源:https://stackoverflow.com/questions/18986200/suppress-safari-cant-open-the-page-because-the-address-is-invalid-custom-app-l

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