Android/ Phonegap - Onclick() Not Working June 12, 2024 Post a Comment I am using phonegap and am trying to detect the onClick, however Android seems to completely ignore it, below is what I am trying: Solution 1: I had the same problem with jQuery, Android seems to ignore the click event in javascript. Originally, my code with jQuery looks like this:$("#element").click(function () { alert("message"); }); CopyI had to change it to:$("#element").on("touchend", function () { alert("message"); }); CopyNot sure if you're using jQuery at all, but hope this helps.Solution 2: Add click event listener to your object with javascript. First add an id to object: <select id="obj_id" name="func" data-native-menu="true"> CopyAnd then call addEventListener() :document.getElementById("obj_id").addEventListener("click", StartButtons, false); CopyPhonegap documentation recomends to run all your javascript code in "deviceready" event. So your code should look like this:main.js:functionStartButtons() { ... } functiononDeviceReady() { ... document.getElementById("obj_id") .addEventListener("click", StartButtons, false); ... } functioninit() { document.addEventListener("deviceready", onDeviceReady, false); } Copyindex.html: ... <scripttype="text/javascript"charset="utf-8"src="main.js"></script></head><bodyonload="init();"> ... <selectid="obj_id"name="func"data-native-menu="true"> ... </body>CopySolution 3: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">delete this code from index.htmlSolution 4: user1183085´s answer is the right one. Android does not recognize click events as web apps do, this makes sence since mobile apps are not web when native, so that is why phonegap was made but since it works with jquery and not native java android libraries directly. I put my code this way:The web buttons or elements onclick to handle all web interfaces, and special buttons or elements ontouchend to handle the mobile interfaces. Here´s a part of my code://this handles the login button events for the mobile touch of the user $("button.login-button").on("touchend", function () {alert('hello touch ! =o' )}); //this handles the login button events for web clicks $("button.login-button").on("click", function () {alert('hello click ! =o' )}); Copythanks user user1183085, that solved my life forever =()Solution 5: Watch out, bind an onclick on an input in Cordova 3.4, doesn't work. But it works great with a div element. Considering, input elements are part of form element, like select element, it may be your problem. Share Post a Comment for "Android/ Phonegap - Onclick() Not Working" Top Question Vertical And Horizontal Align Of Image I have a placeholder (under construction) site which holds … Set CSS Width To 100% + Right Border Is Missing? I set a div's width to 100% of the window. When I apply… Z-index 'breaks' Slideshow Click Buttons I've got this problem where my navbar goes behind my sl… IE11 Textarea Loses Focus If Another Textarea Is Disabled In this fiddle, using ie11 with open Console, input somethi… Playing Mp3 Shoutcast Streams With Html5 Audio In Firefox? I'm trying to play mp3 shoutcast stream radio stations … HTML5 "required" Validation Is Not Showing Error Message In Mozilla Firefox This is a peculiar problem but is happening only in a parti… How To Get Highest Input Field Value In Javascript I want to get highest value of this field. How I can do thi… SVG Animation And Firefox I'm struggle with SVG animation drawing, which is work … Homepage Slow To Load When I go to the homepage of my website after clearing my c… How To Add Vertical Sub-menu To Horizontal Menu Using Css And Html? I want to add a vertical sub-menu to my horizontal menu. I … December 2024 (1) November 2024 (39) October 2024 (66) September 2024 (21) August 2024 (353) July 2024 (334) June 2024 (673) May 2024 (1291) April 2024 (771) March 2024 (1533) February 2024 (1707) January 2024 (1401) December 2023 (1396) November 2023 (420) October 2023 (651) September 2023 (283) August 2023 (323) July 2023 (288) June 2023 (360) May 2023 (225) April 2023 (144) March 2023 (139) February 2023 (167) January 2023 (258) December 2022 (122) November 2022 (232) October 2022 (604) September 2022 (161) August 2022 (285) July 2022 (92) Menu Halaman Statis Beranda © 2022 - Html5 Learning