Cordova - 在应用程序内打开链接

时间:2015-05-22 16:40:12

标签: android angularjs cordova webview

我正在使用cordovaangular处理Android应用程序 我尝试在webview中打开外部链接,但它始终以chrome ...

打开

我试图使用:

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

还有:

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

我失踪了什么?

谢谢:)

3 个答案:

答案 0 :(得分:2)

你应该尝试:

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

OR

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

建议:您应该尝试对您的网址进行编码:myURL = encodeURI(urlStr);

答案 1 :(得分:1)

InAppBroser应该是你想要的。 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);
    }
);

答案 2 :(得分:1)

您可以尝试使用WebViewClient:

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

归功于这篇文章:Link should be open in same web view in Android