How to hide device back functionality in jquery mobile tab (navbar)?

笑着哭i 提交于 2020-01-15 23:50:48

问题


I have developed jquery mobile tab to my page. If my page having 5 tabs, now I'm in 3rd tab. I would like it so that when I press the back button from mobile, it should automatically redirect to the 2nd and 1st tab. Then it should redirect to my home page like another html page.

When I press the back button from device, it'll automatically redirect to my home page not a previous tab page. How to control in jquery mobile? Please do the needful. Thanks in advance.


回答1:


You need to listen to navigate event and check if back button was pressed from data object data.state.direction. If true, $.mobile.changePage() to homepage.

If you're using jQuery Mobile 1.4, $.mobile.pageContiner.pagecontainer("change", "#page");

$(window).on("navigate", function (event, data) {
  if (data.state.direction == "back") {
    $.mobile.changePage("#homepage");
    return false; /* prevent showing previous page */
  }
});

Demo



来源:https://stackoverflow.com/questions/21016195/how-to-hide-device-back-functionality-in-jquery-mobile-tab-navbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!