ANDROID WebView javascript redirect won't work

I am trying to create an Android WebView application. When I click a button in a web browser with the following code:

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

      

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

+3


source to share


3 answers


Have you tried document.location

without property href

?



+1


source


Override WebView's shouldOverrideUrlLoading, for example:



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

      

0


source


use this instead:

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

      

0


source







All Articles