我试图控制后退按钮,但我不能。在这里;
event.keyCode == 27 // That’s for escape
event.keyCode == 8 // That’s for backspace...it's also working on browser, but it doesn’t work on my tablet.
我该怎么做?
我试图控制后退按钮,但我不能。在这里;
event.keyCode == 27 // That’s for escape
event.keyCode == 8 // That’s for backspace...it's also working on browser, but it doesn’t work on my tablet.
我该怎么做?
推荐方法
pagecontainerbeforechange
:https ://jqmtricks.wordpress.com/2014/12/01/detect-back-navigation/
您需要收听navigation
事件和state.direction
.
$(window).on("navigate", function (event, data) {
var direction = data.state.direction;
if (direction == 'back') {
// Do something
}
if (direction == 'forward') {
// Do something else
}
});
jQuery Mobile API: 导航事件
你可以在没有jQuery Mobile的情况下做到这一点
window.addEventListener("hashchange", function(e) {
if(e.oldURL.length > e.newURL.length)
alert("back")
});
<a href="#p2">goto page 2</a> and then use browser's navigation.</div>