简体   繁体   中英

Cordova inappbrowser redirect url to system browser Android only

In summery the question is: using the inappbrowser how do I load external urls using the system browser and stop them from being displayed in the inappbrowser?

More detail

I am using the inappbrowser to display a customer portal website, however there are external links on the portal that I want to display in the system browser.

What I want to be able to do is detect the external URL, open external link in system browser and then make sure the inappbrowser is still showing the same page before the external link is pressed.

I am using the loadstart event to detect the URL and then using window.open(url, '_system'); to open the system browser. The problem is that when the system browser closes the external page is also shown in the inappbrowser.

So initially after loading the system browser I initialised the inappbrowser again with the url I wanted to display. This is fine, but I loose all the session history and the next time the back button is pressed the inappbrowser closes down.

The next thing I tried was to use the execute script functionality:

    app.inAppBrowserRef.executeScript({
        code: "window.open('" + overrideUrl + "', '_blank');"
    }, function () {
        //alert("Redirected!");
    });

This loads the link in the system browser and the page displayed when the system browser is closed is correct. The problem is that the view being displayed is not running my loadstart code, so if I click on the same external link it now loads in the same view and not the system browser. Also if I put some debug in I don't see any evidence that what I am seeing is in the inappbrowser or it does not have my code. I also tried executing window.location = overrideUrl, this didn't work either.

The odd thing is that when I open the url using the chromecustomtab plugin and not the systembrowser the executeScript works as required. So this is to do with running the execute script while the system browser is open. I need to support the system browser in case chrome is not installed on the device.

This must be a common problem so really hoping there is a solution out there.

Thanks in advance!

问题是当系统浏览器打开不正确的浏览器时会松开其事件。我正在打开一个新问题,该问题更相关。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM