2014-09-05 103 views
0

我在使用jQuery Mobile + Phonegap进行页面导航时遇到了问题。 我试图复制Android堆栈导航。Jquery Mobile“Stack”导航问题

这里的情况:

用户没有登录,并在主页

  1. 点击“操作外”,需要被记录下来。
  2. 显示登录页面。
  3. 显示“动作A”页面。

问题是: 当用户按下后退按钮时,它应该返回到主页面而不是登录页面。

但是 “堆” 在历史上是这样的:

主要|登录|操作外

我试图做的:

// return from Login page to Main: 
history.back(); // $.mobile.back(); works the same way in this case. 

// then go to Action A page: 
$.mobile.changePage(pageA); 

但“changepage”是如此这般到该动作的页面,然后返回到登录页面中的“后退”指令后执行。

在Android上,这是一项非常简单的任务。 :(

+0

查看changehash选项:http://api.jquerymobile.com/jQuery.mobile.changePage/ – ezanker 2014-09-05 21:09:22

回答

0

只是不叫 “回”,并导航到下一个页面。

在“ onBackPressed“事件处理程序检查JQM堆栈并使用history.go(-2)。例如:

var index = $.mobile.navigate.history.activeIndex - 1; 
if (index >= 0) { 
    var backStep = -1; // back one by default 
    var hash; 
    while (index > 0) { 
     hash = $.mobile.navigate.history.stack[ index ].hash; 

     if (hash == "#pageLogin") { 
      backStep--; 
     } 

     index--; 
    } 

    window.history.go(backStep); 
} 
0

您可以使用

window.history.go(-2) //Go two pages back 

或相同的方法两次

history.back(); //Go one page back 
history.back(); //Go another one page back