Phonegap jQuery event.target not working

I have a PhoneGap-iOS app for iPad where the user will receive a pop-up exit window, as shown in the figure below.

Logout popup

I want this popup to hide when the user clicks on Body. My code , which works in its own browser, does not work on iPad Simulator .

 $("body").ClickOrTouch(function (evt) { if (!(evt.target.id == "launchUsername") { $('#launchLogout').hide(); } }); 
+6
source share
4 answers

On iPhone iPad, the click event will only work in the anchor tag, but not for span or div tags, so try this, it will work.

 $("body").on('click touchend', function (evt) { if (!(evt.target.id == "launchUsername") { $('#launchLogout').hide(); } }); 
+3
source

Maybe event.touches[0].target can do this on a mobile safari (you have an array of orders to manage multi-touch events with one finger). As discussed in this section: Mobile Safari - event.target in touch event

But I think it's worth trying jquery-ui-touch-punch .

This is what I use to control touch events using jquery on a mobile web application (e.g. cordova / phonegap)

Very simple: simply by adding this library, any touh event behaves like mouse events.

(press down / up => mouse down / up, one click => click, etc.)

+2
source
 $("body").on('touchend', function (evt) { if (!(evt.target.id == "launchUsername") { $('#launchLogout').hide(); }else{ evt.stopPropagation(); } }); 
+2
source

Have you tried another event? something like that?

 $("body").on('touchend', function (evt) { if (!(evt.target.id == "launchUsername") { $('#launchLogout').hide(); } }); 
+1
source

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


All Articles