1

I'm working on android application with cordova and angular.
I try to open external link inside the webview, but it's always opens in chrome...

I tried to use:

navigator.app.loadUrl(link, {openExternal:false})

and also:

window.open(link, '_self', 'location=yes')

What i'm missing?

Thank you :)

Yehuda
  • 1,382
  • 3
  • 18
  • 25
  • If you open an external link inside your app you will break everything and you won't be able to go back to your app, don't do it. – jcesarmobile May 25 '15 at 08:20

3 Answers3

1

InAppBroser should be you want. https://cordova.apache.org/docs/en/3.0.0/cordova_inappbrowser_inappbrowser.md.html

http://cordova.apache.org/docs/en/2.5.0/cordova_file_file.md.html

// !! Assumes filePath is a valid path on the device

var fileTransfer = new FileTransfer();
var uri = encodeURI("http://some.server.com/download.php");

fileTransfer.download(
    uri,
    filePath,
    function(entry) {
        console.log("download complete: " + entry.fullPath);
    },
    function(error) {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("upload error code" + error.code);
    }
);
Nicol
  • 234
  • 1
  • 5
  • InAppBrowser not good for me because I need to allow the user to download from the external link and InAppBrowser didn't support downloading... – Yehuda May 22 '15 at 16:50
  • webview not support download,need native implement; you can use http://cordova.apache.org/docs/en/2.5.0/cordova_file_file.md.html – Nicol May 22 '15 at 17:35
  • But how can I use it? I want to allow the user to download from a website that not belong to me :( – Yehuda May 22 '15 at 17:38
  • @Yehuda, you have another question where you got an answer about how to make inAppBrowser plugin download files. – jcesarmobile May 25 '15 at 08:19
1

You should try :

window.open(myURL, '_blank'); => OPEN IN INAPPBROWSER 

OR

window.open(myURL, '_system');  => OPEN IN SYSTEM BROWSER

ADVICE : you should try to encode your URL : myURL = encodeURI(urlStr);

Nicolas2bert
  • 1,142
  • 7
  • 10
1

you can try use WebViewClient:

webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView viewx, String urlx) {
            viewx.loadUrl(urlx);
            return false;
        }
    });

Credit goes to this post: Link should be open in same web view in Android

Community
  • 1
  • 1
uiltonsantos
  • 409
  • 4
  • 9