Enabling general JavaScript in WebViewClient

前端 未结 8 677
醉梦人生
醉梦人生 2020-11-29 03:32

While searching for an answer in google, it seems that I\'m not the only one stuck with a problem that seems impossible to solve.

I\'ve managed to create a WebView w

相关标签:
8条回答
  • 2020-11-29 03:37

    Do "Javascript-URLs" get routed through shouldOverrideUrlLoading? Try checking that and if so, return false for links like that (so that the webview handles the link, not your WebViewClient)

    0 讨论(0)
  • 2020-11-29 03:38

    How enable programmatically answered in other answers. But some javascripts not worked if your webview is in nestedscrollview. Remove it and add webSettings.setJavaScriptEnabled(true);

    0 讨论(0)
  • 2020-11-29 03:39

    What happened in my case : I was serving local html files and when applying

        web.getSettings().setJavaScriptEnabled(true);
        web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    

    but then my urls stopped working. Solution to make both JS and local href work was to add

        web.getSettings().setAllowFileAccess(true);
        web.getSettings().setAllowFileAccessFromFileURLs(true);
    

    where

        web = (WebView) findViewById(R.id.embedded_web);
    
    0 讨论(0)
  • 2020-11-29 03:42

    Try this to enable javascript

    WebView myWebView = (WebView) findViewById(R.id.webView);
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl(url);
    
    0 讨论(0)
  • 2020-11-29 03:43

    The proper way to enable JavaScript is by add the below two lines:

    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    

    Even if after adding its not working then try adding the below line.

    mWebView.getSettings().setDomStorageEnabled(true);
    

    Now It should work. :)

    0 讨论(0)
  • 2020-11-29 03:50

    I don't know what your exact problem is, but i can enable the JavaScript and a custom WebViewclient without any problem:

    WebView vistaWeb = (WebView) findViewById(R.id.webview);
    vistaWeb.setWebChromeClient(new MyCustomChromeClient(this));
    vistaWeb.setWebViewClient(new MyCustomWebViewClient(this));
    vistaWeb.clearCache(true);
    vistaWeb.clearHistory();
    vistaWeb.getSettings().setJavaScriptEnabled(true);
    vistaWeb.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    
    0 讨论(0)
提交回复
热议问题