'Is it possible to open a URL in a client default mobile browser while the click originated from an in app browser?

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>




Solution 1:[1]

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);
}

Solution 2:[2]

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.

Solution 3:[3]

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.

Solution 4:[4]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SuperSaiyan99000
Solution 2 Dsymbol
Solution 3
Solution 4 Fahad