Android webview javascript seems not working on Sony Xperia

自作多情 提交于 2019-12-24 07:18:09

问题


I have tested my app on HTC and MI2 and some samsung devices, and it worked fine.

However on Sony devices, it is not working at all.

Java Code:

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new TestInterface(), "jsjava");

    public class TestInterface {
        @JavascriptInterface
        public void login() {
            Log.d("TEST", "js call java ok");
        }
    }

Html and js code:

<script>
    function login(response){
        window.jsjava.login();
    }
</script>

<div class="land"><a href="javascript:login();">Login</a></div>

The log message "js call java ok" does not show up on sony devices, like the xperia.

I made sure to enable javascript support on device, but it is still not working.

Please help.


回答1:


Solved!

Add

webView.setWebChromeClient(new WebChromeClient());

after

webView.getSettings().setJavaScriptEnabled(true);

And add @JavascriptInterface to every function that will called from javascript.



来源:https://stackoverflow.com/questions/24933111/android-webview-javascript-seems-not-working-on-sony-xperia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!