Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>


like image 589
Subjugation Avatar asked Nov 29 '25 09:11

Subjugation


1 Answers

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.

like image 95
fsw Avatar answered Nov 30 '25 23:11

fsw