Jquery mobile ''pagebeforeshow' not executing after pressing back

落花浮王杯 提交于 2019-12-12 06:57:02

问题


i have implemented some logic inside

$(document).on('pagebeforeshow', '#mainPage', function(){ 
}

but it doesnt load when a user eitehr presses the back key to go back to this specific page containg this JS or when calling

history.back(-1); return false;

to manually go back to the previous page.

It only gets executed if you do a refresh or directly go to the page using a href<>

Any sugestions?

cheers


回答1:


Since you're using multi-files template, you need to fetch previous URL from history document.referrer.

Demo

$('.selector').on('click', function (e) {
  e.preventDefault();
  var page = document.referrer;
  $.mobile.changePage(page, {
    transition: 'flip',
    reloadPage: true, // optional, force page reload.
    reverse: true
  });
});


来源:https://stackoverflow.com/questions/17700177/jquery-mobile-pagebeforeshow-not-executing-after-pressing-back

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