Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANDROID WebView javascript redirect won't work

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.

like image 251
UNTITLED.PNG Avatar asked May 08 '17 12:05

UNTITLED.PNG


1 Answers

Override the WebView shouldOverrideUrlLoading, like this:

myWebView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
like image 178
Santiago Avatar answered Sep 26 '22 01:09

Santiago