あなたの場合、pagebeforechange
イベントをリッスンして表示を渡しdata.toPage
、別のイベントを表示する必要があります。
pagebeforehide
andを使用するとpagebeforeshow
、表示data.toPage
され、目的のページにジャンプします。
デモ
// for demo purposes
var condition = 0;
// triggers when leaving any page
$(document).on("pagebeforechange", function (e, data) {
// id of page that you want to skip if condition is true/false, it's up to you
var to_page = data.toPage[0].id;
// skip showing #myPage if condition is true
if (to_page == "myPage" && condition == 0) {
// true! go to p3 instead
$.mobile.changePage("#p3", {
transition: "flip"
});
/* prevent updating URL history and allow new transition if you want.
Without this, #myPage will be pushed into $.mobile.urlHistory
and any new transition (animation) will be neglected */
e.preventDefault();
}
/* in the demo, if you change condition value, #p2 will be shown
when condition returns "false". #myPage will be shown normally */
});
注: pagebeforechange
2 回発火しますが、これは正常です。パニックにならないでください ;)