Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery click not working with ipad

we have a web application which is using Jquery blockUI to open a pop up and do some action. All of this works fine on Safari, and IE 8. problem is with Ipad. none of the actions in pop up are responding. it just stays on that page. even close doesnot work. do we need to add anything else? here is the code that opens a page and click event for close.

<script> $(document).ready(function() {   $.ajaxSetup( {            cache:false    });          $("#sendInviteDiv").load("invite.htm?action=view&pid="+pid);             $.blockUI({ message: $('#sendInviteDiv'),                 centerY: 0,                     css: {                 top:  ($(window).height() - 550) /2 + 'px',                         left: ($(window).width() - 870) /2 + 'px',                         width: '870px'                 }             });             //var ua = navigator.userAgent;             //var event = (ua.match(/iPad/i)) ? "touchstart" : "click";             //alert(ua);              $('#closeInvite').click($.unblockUI);      $('#inviteBtn').click(function() { //script to load         //setPositionDetails('${formName}','inviteBtn');         }); }   });   </script> 

appreciate pointers.

javascript is turned on and popups are allowed in Ipad Safari settings.

like image 496
Atchuta Vani Avatar asked Oct 25 '11 16:10

Atchuta Vani


People also ask

Why can't I click on my iPad?

Restarting your device often fixes common issues like a frozen screen. Here's how to do it. If your iPad has a Home button: Press and hold the top and Home buttons at the same time. When you see the Apple® logo, release both buttons.

Is JavaScript compatible with iPad?

JavaScript is turned on by default for iPhone and iPad.


2 Answers

I usually use

.bind("click touchstart", function(){  }); 

instead of:

.click(function(){  }); 

That way you are binding the the correct event. It's also quicker, the touch responds much faster than click for some reason.

like image 89
Rich Bradshaw Avatar answered Oct 01 '22 12:10

Rich Bradshaw


I know this was asked a long time ago but I found an answer while searching for this exact question.

There are two solutions.

You can either set an empty onlick attribute on the html element:

<div class="clickElement" onclick=""></div> 

Or you can add it in css by setting the pointer cursor:

.clickElement { cursor:pointer } 

The problem is that on ipad, the first click on a non-anchor element registers as a hover. This is not really a bug, because it helps with sites that have hover-menus that haven't been tablet/mobile optimised. Setting the cursor or adding an empty onclick attribute tells the browser that the element is indeed a clickable area.

(via http://www.mitch-solutions.com/blog/17-ipad-jquery-live-click-events-not-working)

like image 38
lachie_h Avatar answered Oct 01 '22 13:10

lachie_h