Reputation: 19969
I have the following markup:
<div class="event-row-container">
<div data-id="1" class="ios-location-name">Location Name</div>
<div data-id="1" class="ios-location-detail" style="display: block;">
700 S Grand Ave<br>
Omaha<br>
</div>
</div>
and the following jQuery:
$('.ios-location-name').click(function(){
var event_id=$(this).data('id');
alert('you clicked event_id:' + event_id);
$('.ios-location-detail').toggle();
});
Works on all browsers but not on an embedded UIWebView on iOS5.1 (simulator or device). Should this work? Is there somethign I'm missing?
thx
edit #1 so is there an EASY soln't of getting this to work?
Upvotes: 3
Views: 5627
Reputation: 37065
As you've already read, there are a few issues that could be the cause:
click
events nativelySo for the second issue (found here) try changing:
<script src="js/jquery-1.7.2.min.js"></script>
to
<script src="jquery-1.7.2.min.js"></script>
(obviously the file names and paths will need adjusting, but the bottom line is to just refer to the file names without the full base path).
For the first, you already indicated that the solution at: How to implement touch events in uiwebview?
Didn't work. Have you tried one of the open source libraries recommended at: send a notification from javascript in UIWebView to ObjectiveC
Specifically, PhoneGap looks pretty snazzy to me, but whichever fixes the problem is the best one, obviously.
But the overall issue for why it works in Safari mobile but not UIWebView is because the events are not mapped/cross-referenced.
One last idea, just to say you tried it... Try changing your code to either:
$('.ios-location-name').on("click", function(){
just in case they are somewhere way back there mapped, but the click
method itself isn't mapped to the touch event (even though the the click event might be). Worth a shot. But I'd try out the first two ideas just to see if life can be easy.
Upvotes: 4