0

I am using the fastklick plugin for iOS what is very popular on the net for speeding the click event on jquery mobile apps with phonegap on iOS.

The buttons and links are working very well except the back button from jquery.

If I use this:

<div data-role="page" id="test" data-add-back-btn="true">

then if I want to click on the button, there is already the delay from iOS. The button is getting blue at first and after that the page is sliding. How can I prevent this so this button is working fast like the other buttons I am creating with

<button>...</button>?

Is it possible to create my own back button and apply an event to it?

user229044
  • 232,980
  • 40
  • 330
  • 338
Mutatos
  • 1,675
  • 4
  • 25
  • 55

1 Answers1

1

First remove data-add-back-btn="true" then you can try this:

<a class="ui-btn-left" data-icon="arrow-l" href="javascript:history.back(1) " data-theme="a">Back</a>

or this:

<a class="ui-btn-left" data-icon="arrow-l" href="#" data-theme="a" id="back-btn">Back</a>

$('#back-btn').bind('touchstart', function(e) {
    $.mobile.changePage("#pageID");
}); 

Just change #pageID to your real page ID. touchstart event is great for back button if you are just doing it and not a page scrolling.

Gajotres
  • 57,309
  • 16
  • 102
  • 130
  • Hmm ok, but this means I need to know on each page, where (which #pageId) the back button should go. – Mutatos Dec 19 '12 at 19:37
  • Btw: Is it better to use "touchstart" or maybe "vclick"? – Mutatos Dec 19 '12 at 19:38
  • The touchstart (or touchend) event works great if you know the user won't be scrolling. That's actually the reason click events take so long to resolve on mobile devices, the device is waiting to see if the user is scrolling or clicking. – Gajotres Dec 19 '12 at 19:46
  • At least try to experiment with my second example, in case it is working find a way to incorporate it into your app. – Gajotres Dec 19 '12 at 19:47
  • And whats happen if the user is scrolling? Should I use insteat touchstart and touchend, vlick? – Mutatos Dec 20 '12 at 13:07
  • You don't need to care about scrolling because you are using this event on back button. No matter what is user doing when he click back button touchstart will trigger changePage (no need to worry about scrolling). – Gajotres Dec 20 '12 at 13:11