Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a web page which contains some divs with id option and jquery event that make some changes when you click on one of those divs. jQuery event works perfectly for desktop and Android users, but there are some issues with web page for iPhones. For some iPhones, this event is not working, I tested different iPhones and I discovered:

Some things you need to know

  • For some iPhone 11, event is not working.
  • For Iphone XS, divs are not clickable
  • Divs are perfectly styled for iPhones
  • They are not overlapping each other or any other element in web page
  • The web page works flawlessly on iPhone 12 and 13 devices.
  • I'm using jQuery version 3.6.1.
  • During testing on Xcode for different simulation, the div was clickable.


This is the code for the event:

JavaScript
$(".option").on("click", function(event) {
  event.preventDefault();

  let dataCur = $(this).data("cur");
  let imageUrl = $(this).find(".pm_select_img img").attr("src");
  let optionText = $(this).find("span").text();
  
  $("#firstBtn .pm_select_img img").attr("src", imageUrl);
  $("#firstBtn span").text(optionText);
  $("#firstBtn").data("cur", dataCur);
  
  $("#currency1 .pm_select_child").attr("data-cur", dataCur).text(dataCur);
  $("#hiddenInput").val(dataCur);
  
  $("#amount_send1").attr("data-cur", dataCur);
  $("#amount_send1 ~ .addons").text(dataCur);

  const secondDataCur = $("#currency2 a").data("cur");
  fetch("/calculateExchangeRate",{
    method: "POST",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      firstCryptoCurrencySymbol: dataCur,
      secondCryptoCurrencySymbol: secondDataCur
    })
  })
  .then(res => res.json())
  .then(data => {
    const exchangeRate = data.rate;
    $(".rate_info").text(`1 ${dataCur} = ${exchangeRate} ${secondDataCur}`);
  });

  $("#firstDrop").toggle();
});


What I have tried:

  • During testing on Xcode for different simulation, the div was clickable.
  • I tried adding touchstart and touchend but it didn't help
  • I tested the web page on three different iPhone 11 devices, and on two of them, the div was not clickable.
Posted
Updated 10-Aug-23 7:20am
v2
Comments
Member 15627495 5-Aug-23 2:06am    
don't make confusion between IOS and Safari.
'Os' are not 'web browser'.

in a first time, make a 'reset' of Safari on the 'faulty testing phone'.


don't erase/modify your code.

let the page loading fully, be patient, if you make your test too quickly, you'll have 'a bad feedback' for a mistaken result.

about JQUERY :
- do you use $().ready(){} // it's the best status of 'web page'. at this point, all the content is loaded and the page is ready.

1 solution

I don't think this is an iPhone issue but more related to the default browser in iPhone which is Safari.

The first thing I will try is to use the Use 'touchstart' event as some mobile devices behave better with the 'touchstart' event compared to the 'click' event -
JavaScript
$(".option").on("click touchstart", function(event) {
  // Your existing event handling code here
});


Secondly, I will test on a real devise as the 'Xcode' simulator might not fully replicate a real-world device behavior.

Try to connect an iPhone where the click does not fire, directly to your pc and use Safari's Web Inspector to debug the web page in real-time. This way you can inspect elements, check event listeners, and debug JavaScript directly on the device, check for any console errors or warnings that might be causing the event handler to fail.

Lastly, I will try running the web page on different browsers (Safari, Chrome, Firefox) on the problematic iPhone to see if the issue is specific to a certain browser or just Safari.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900