How to go back in jquery mobile without triggering

2019-06-01 09:12发布

问题:

Going back in jquery mobile will trigger a $.mobile.changePage() with the location.hash as explained in the jquery mobile docs.

I wan't to be able to do a history.go(-N) without anything happening except the history of the browser being shortened by the last N elements.

So I wish to avoid the animation of $.mobile.changePage() that will hide and show a different page.

Is it possible ?, and how can I achieve this ?

回答1:

This what I did, but I'm not happy at all with it. But it does the trick.

$.mobile.hashListeningEnabled = false;
history.go(-history_steps);
...

setTimeout(function() {
   $.mobile.hashListeningEnabled = true;
}, 300);

The timeout is here to try to re-enable the normal behavior after the real hashchange event is triggered.

I would be really happy if someone could have a better solution.



回答2:

There is "rel=external" function in jQueryMobile and it won't trigger the animation.