【问题标题】:JQueryMobile - pagecontainerbeforeshow: remove previous page from historyJQuery Mobile - pagecontainer beforeshow:从历史记录中删除上一页
【发布时间】:2019-09-21 02:06:33
【问题描述】:

使用 jquery 和回调 pagecontainerbeforeshow 我想从 navigationhistory 中删除上一页 - 也就是说,如果用户从 page1 导航到 page2,并且用户单击后退按钮我想退出“应用程序”。

我在这里发现了同样的问题,但我不知道如何在 pagecontainerbeforeshow 中实现答案?

Jquery mobile, remove previous page

 bindEvents: function() {

    $(document).on("pagecontainerbeforeshow", function(event,ui){

        var destinationPage = ui.toPage.prop("id");
        var sourcePage = ui.prevPage.prop("id");

        d.lg("destionationPage: " + destinationPage);
        d.lg("sourcePage: " + sourcePage);
        console.log("page to be shown =" + destinationPage);
        switch(destinationPage) {
            case 'restaurants':
                d.lg('redirected to list');

            break;
            case 'offers':

                d.lg('redirected to offers');

            break;

            }
        }); 
}

【问题讨论】:

  • 提示:你需要pagecontainerbeforechange事件。

标签: jquery html jquery-mobile


【解决方案1】:

Bohr 最终使用了an alternative to change the back button behaviour

如果存在带有id=the_id_id_of_the_pagediv

  1. pagecontainerbeforeshow 事件中,backbutton 将与backButtonExit() 函数相关联
  2. backButtonExit() 函数会触发应用退出

    navigator.app.exitApp()
    
  3. pagehide 上,backButtonExit 函数将从button 中删除,并且该行为将停止

    $("#the_div_id_of_the_page").on('pagecontainerbeforeshow',function(){
      document.addEventListener("backbutton", backButtonExit,false);
    })
    
    $("#the_id_id_of_the_page").on('pagecontainerhide',function(){
      document.removeEventListener("backbutton", backButtonExit,false);
    })
    
    function backButtonExit(){
       // Phonegap
       navigator.app.exitApp();
       // Normal Browser
       window.close()
    }
    

这是一个比您的解决方案更简单的解决方案,但如果您需要,它也可以集成到您的switch 语句中。另外,如果您没有使用 phonegap consider reading this post

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-01
  • 2012-10-26
  • 2019-08-06
  • 2017-11-02
  • 1970-01-01
  • 1970-01-01
  • 2022-11-03
相关资源
最近更新 更多