Android: can't get javascript to work on WebView even with setJavaScriptEnabled(true)

后端 未结 3 880
闹比i
闹比i 2020-12-19 08:13

I\'m a complete noob to Android and this is just a simple test. Based it on this tutorial.

Here goes the HelloWebApp.java

package com.company.somethi         


        
相关标签:
3条回答
  • 2020-12-19 08:18

    just add

    import android.webkit.WebChromeClient;
    import android.webkit.WebView;
    

    in YourApp.java

    0 讨论(0)
  • 2020-12-19 08:24

    As discussed in https://stackoverflow.com/a/7561674/1818089,

    along with

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebChromeClient(new WebChromeClient());
    

    you need to enable DOM storage

    WebSettings webSettings = webView.getSettings();
    webSettings.setDomStorageEnabled(true);
    
    0 讨论(0)
  • 2020-12-19 08:34

    You missed the part in the tutorial where he adds

    webView.setWebChromeClient(new WebChromeClient());
    

    right after adding

    webView.getSettings().setJavaScriptEnabled(true);
    

    The JavaDoc for this method says:

    Sets the chrome handler. This is an implementation of WebChromeClient for use in handling Javascript dialogs, favicons, titles, and the progress. This will replace the current handler.

    0 讨论(0)
提交回复
热议问题