Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - JavaScript : touchstart event not fired until zoom or scroll the page

In my Android application, The user can browse some HTML pages using ViewPager, and the user can touch an element to highlight.

the problem is when trying to get the touch event using javascript using the following code, elementFromPoint returns null when navigate to new page, but after the user zoom the page or scroll on it, it works right.

I found that register of the touchstart event happens after zoom or scroll the page. so it works right after that although it is registered on $(document).ready()

        $(document).ready(function(){
            document.addEventListener("touchstart", touchstart, false);     
        });     

        function touchstart(e) {                              
            var x = e.targetTouches[0].clientX; 
            var y = e.targetTouches[0].clientY;                             
             el = document.elementFromPoint(x, y);  
            }

Thank you

like image 945
Ahmed Al Khashab Avatar asked Jan 23 '13 10:01

Ahmed Al Khashab


Video Answer


1 Answers

write next code in your java code after calling javascript :

    myWebview.scrollTo(1, 0);
    myWebview.scrollTo(0, 0);

or use zoom in then zoom out

    myWebview.zoomIn();
    myWebview.zoomOut();
like image 110
Mohamed Abdel Latif Avatar answered Oct 14 '22 08:10

Mohamed Abdel Latif