8

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?

Garfex
  • 111
  • 1
  • 4

3 Answers3

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.

Łukasz Zaroda
  • 869
  • 2
  • 19
  • 55
Brijesh Masrani
  • 1,439
  • 3
  • 16
  • 27
  • I put a breakpoint all over this function and my method never goes in here. I tried before and after my webview loads a page. – CQM Jul 28 '11 at 15:18
1

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

Imran Omar Bukhsh
  • 7,849
  • 12
  • 59
  • 81
1

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>
Community
  • 1
  • 1
Ari Lacenski
  • 631
  • 12
  • 18