Android Webview Javascript click event, not fire, as it should

I have a webpage with a lot of different DOM settings where click events are bound.

But in some cases, click events do not fire. I wrote all my events the same way: $ ('# Element') press (function () {...}) ;.

I narrowed it down to just warn something when I click on those elements that don't work. but nothing happens.

This only happens on an Android mobile phone: Note Samsung Galaxy 4.1.2 Samsung Galaxy s3 Mini 4.1.2 When I launch webview, if I launch it in the Chrome browser, it works fine.

In general, click events are placed in 'a' tags, with shortcuts and input type inside.

Are there any unknown rules for not using tags or shortcuts in it or something that pops this for the Android browser? Or is there another solution for this kind of error?

PS. When I click an item several times (5-6 times) after eachother, it disappears ...

+4
source share
3 answers

Have you enabled javascript for your webview?

webView.getSettings().setJavaScriptEnabled(true); 
+4
source

First of all, you should not use .click() as it is deprecated. Use instead

 $('#id').on('click', function(event) { //whatever }); 

Are elements dynamically inserted using javascript? If so, you will need to use event delegation, as yshrsmz suggests. In addition, in your example, you write #element , this points to an element with the identifier element , you should use only one identifier in dom. Instead, apply the class to all the elements that should trigger the click.

Make sure all the bindings are set on the finished document.

It's probably worth running your HTML code through the W3C validator to make sure that it is all valid. This can lead to errors if not.

Finally, check your Android log code, see if there are any error messages when clicking items.

+1
source

if you use delegation delegation instead of the usual click event, that will be fine ... (most of the time)

 $(document).on('click', '#element', function(){}); 
0
source

Source: https://habr.com/ru/post/1491670/


All Articles