最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript sometimes doesn't work in android's webview - Stack Overflow

programmeradmin4浏览0评论

I put a webview in my application to visit a webpage which includes some javascript functions, my purpose is when users click a link in the webpage, it will start a new activity in the application. I've written "webSettings.setJavaScriptEnabled(true);" in my source codes.

It works well in most of the time, however sometimes it doesn't work, there is no response when users click, and I don't know why because the environment is not changed at all. Has anybody know why?

I put a webview in my application to visit a webpage which includes some javascript functions, my purpose is when users click a link in the webpage, it will start a new activity in the application. I've written "webSettings.setJavaScriptEnabled(true);" in my source codes.

It works well in most of the time, however sometimes it doesn't work, there is no response when users click, and I don't know why because the environment is not changed at all. Has anybody know why?

Share asked Jul 22, 2010 at 7:04 GarfexGarfex 1111 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3
v.setWebChromeClient(new WebChromeClient() {
    @Override
    public void onConsoleMessage(String message, int lineNumber,String sourceID) {
        Log.d("MyApplication", message + " -- From line "+ lineNumber + " of " + sourceID);
        super.onConsoleMessage(message, lineNumber, sourceID);
    }
});

check this code so at least you will get error message and one more thing is that android doesn't supports all JavaScript functions.

I had the same issue. I changed the event for from 'click' to 'touchstart' and now its awesome.

Credit is due to Imran Omar Buksh for this idea.

... other HTML ...

    </body>
    <script type="text/javascript">
        document.querySelector("#checkItOut").addEventListener("touchstart", 
            function() {
                jsObject.performClick();
        });
    </script>
</html>
发布评论

评论列表(0)

  1. 暂无评论