admin管理员组

文章数量:1279017

I'm trying to create a Android WebView app. When I press a button in the webview with the following code behind it:

window.location.href = "";

Nothing happens, but in the chrome browser on Android it will work. I can also confirm that javascript is enabled because I can change the backgrond color by using javascript in the webview.

I'm trying to create a Android WebView app. When I press a button in the webview with the following code behind it:

window.location.href = "https://www.example.nl";

Nothing happens, but in the chrome browser on Android it will work. I can also confirm that javascript is enabled because I can change the backgrond color by using javascript in the webview.

Share Improve this question asked May 8, 2017 at 12:49 UNTITLED.PNGUNTITLED.PNG 5312 gold badges6 silver badges13 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

use this instead:

window.open("https://www.example.nl", "_self")

Override the WebView shouldOverrideUrlLoading, like this:

myWebView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

Did you try document.location without the href property ?

本文标签: javaANDROID WebView javascript redirect won39t workStack Overflow