2

The answer might be a resounding no, but I figured I'd ask anyway. I realize this might be a security nightmare.

I created the following test page that checks whether or not the user is using an in app browser or not and displays a link accordingly.

When the user does use an in app browser, I am displaying the "continue here" link and I would like him to be prompted to choose to open the link in his mobile's default browser rather than in the in app browser he is currently using.

<html>
<body>
<a id="btn" href="#" onclick="window.open('https://www.google.com', '_system'); return false;">Continue here</a>
<a id="btn2">not in app browser</a>
</body>
</html>



<script>
    webviewCheck();
    function webviewCheck() {
        let standalone = window.navigator.standalone,
            userAgent = window.navigator.userAgent.toLowerCase(),
            safari = /safari/.test(userAgent),
            ios = /iphone|ipod|ipad/.test(userAgent);

        if (ios) {
            if (!standalone && safari) {
                // Safari
                console.log("safari browser is being used");
                document.getElementById("btn").hidden=true;
            } else if (!standalone && !safari) {
                // iOS webview
                console.log("IOS webview is being used");
                document.getElementById("btn2").hidden=true;
            };
        } else {
            if (userAgent.includes('wv')) {
                // Android webview
                console.log("Android webview is being used");
                document.getElementById("btn2").hidden=true;
            } else {
                // Chrome
                console.log("Other browser is being used (firefox/chrome/edge/etc)");
                document.getElementById("btn").hidden=true;
            }
        };
    }
</script>


Subjugation
  • 105
  • 2
  • 10
  • No idea about IOS but on Android the handling of URLs launched within apps is fully dependent upon the intents declared within the app manifest. There is no way your website can hijack the behaviour of someone's app. – miknik May 29 '22 at 01:26

4 Answers4

1

This should force system browser on Android/iOS:

window.open(url, '_system');

But this will also continue using system browser when executed on system browser so not sure why you want to distinguish those cases.

fsw
  • 3,595
  • 3
  • 20
  • 34
0

maybe this can be helpful Can I make a link that will open in my app if it's installed, and fall back to a different URL if not?

function openLink () {
    var appWindow = window.open("ourapp://www.ourdomain.com/files/12345","_blank");
    setTimeout( function () {if (appWindow) {
        appWindow.location ="http://www.ourdomain.com/buyourapp";
            }
            },1000);
}
-1

the best way to check the app browser what I think you have to check the resolution of the screen by using javascript.

Fahad
  • 15
  • 6
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 27 '22 at 03:16
-1

Yes, it's very much possible if the user is logged in. You will have to make a database column of maybe boolean field.

can_open_url = False

Whenever the user performed the action, you will allow it to touch your database and update your filed,

can_open_url = True

With the help of ajax or fetch, you can trigger the function in your (backend code) upon user's gesture in the browser, and ask if the the field is True, something like this:

    if(can_open_url === true){
        window.location.href = '/my_url/'; or
        if(window.location.href != "/my_url/"){
            window.location.replace("/my_url");
}

or you can still open a new window as you did. Then re-update the boolean field to its formal value after a successful manipulation.

The main transaction will take place on your backend, because you will have to know all the browsers where the user is logged in and with that you can query the one where the URL will be opened for the user.

I don't know the backend you are using. If you specify your backend i may still give you more hand on a way to do it, only if you feel the answer may be helpful.

Dsymbol
  • 29
  • 1
  • 6