JQM:如何在内部第二页上的“data-rel ='back'”按钮后检测首页重新加载?

时间:2012-10-21 18:03:02

标签: jquery-mobile

我正在编写一个jQuery-mobile应用程序。

在我的家(“第一个”)页面中,我使用自定义链接(< a href =“...”>)链接内部(“第二”)页面。

在我的第一页中,我需要检测用户点击第二页上的“data-rel ='back'”按钮(第一页将再次显示)。 我确实试过了

    $(document).bind('pageinit')

    $(document).bind('pageshow')

没有成功。 请注意,使用

    rel="external"

$(文件).bind('pageinit')会解雇,但那不是我想要的......

1 个答案:

答案 0 :(得分:0)

尝试使用$.mobile.urlHistoryHow to modify jQuery mobile history Back Button behavior)。它有activeIndex,它是历史堆栈中的当前索引,previousIndex,这当然是您以前的索引。

因此,要通过点击“返回”按钮来检测用户是否来自您的第二页,您可以:

检查他们来自的网页的哈希值:

var previous = $.mobile.urlHistory.previousIndex;
var origin = $.mobile.urlHistory.stack[previous].hash; //you may need to do some regex here
if ( origin === "second" )

或一般:

// user clicked on 'back' button
if ( $.mobile.urlHistory.activeIndex < $.mobile.urlHistory.previousIndex)