Suppress Safari can't open the page because th

2019-03-13 02:51发布

问题:

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')"