3

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?

timpone
  • 19,235
  • 36
  • 121
  • 211
  • I've tried in couple IOS browsers including iPhone simulator and it seems working!!!! – Jay May 01 '12 at 01:59
  • which simulators? I've tried in iOS Simulator app and on device and not working on either. This first time putting jQuery on iOS device so am very, very new. thx – timpone May 01 '12 at 02:00
  • iPhone Simulator. Even I tried in my iPhone and iPad and it seems working. Here is the jsfiddle: http://jsfiddle.net/RHDqM/ – Jay May 01 '12 at 02:02
  • is it alerting you? I'm getting nothing. I was hiding the ios-location-detail and should be toggling it open. I have 3GS with 5.1. – timpone May 01 '12 at 02:05
  • Yes it is alerting me first and then toggling the div. My iphone is 4GS and my simulator version is 4.1 (225) and i have a first generation iPad. By the way I just tried that in my wife's iphone which is 3Gs and its working in 3Gs as well as 4GS. – Jay May 01 '12 at 02:10
  • Do I need to do anything special to fire it like a command or option key? I'm just clicking like it's a link and nothing is happening – timpone May 01 '12 at 02:14
  • No, I just simply clicked it. Thats it. What are you trying to do? Give me the actual link. – Jay May 01 '12 at 02:15
  • http://arclocal.com/test-javascript.html let me know if its working for you – timpone May 01 '12 at 02:20

2 Answers2

4

As you've already read, there are a few issues that could be the cause:

  1. UIWebView doesn't register click events natively
  2. Scripts don't need (and apparently shouldn't have) full path locations in their src/href.

So 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.

Community
  • 1
  • 1
Anthony
  • 36,459
  • 25
  • 97
  • 163
0

Here is the simulator screenshot. Its working here.

enter image description here

Jay
  • 1,384
  • 1
  • 17
  • 30
  • so is it works on safari but not on UIWebView. :-( Any idea why this wouldn't be working on UIWebView? – timpone May 01 '12 at 03:10
  • so amazingly, it looks like this doesn't work: http://stackoverflow.com/questions/6260627/how-to-implement-touch-events-in-uiwebview – timpone May 01 '12 at 03:19