问题
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