Jquery mobile 在我的jQueryMobile历史记录中查找my index.html(第一个)页面
我正在使用jQMobile的单页AJAX加载。每个页面都是自己的文件 需要时,我会在页面上动态创建主页按钮。今天我只使用一个指向“index.html”的标记。有什么方法可以检查我的web应用程序jQueryMobile历史记录,找到历史上第一次加载index.html页面的地方,并调用window.history.back(-##);添加到页面,而不仅仅是添加到历史记录和导航 代码将是这样的,如果历史记录中没有index.html,我将只使用window.location.href访问页面Jquery mobile 在我的jQueryMobile历史记录中查找my index.html(第一个)页面,jquery-mobile,back,browser-history,Jquery Mobile,Back,Browser History,我正在使用jQMobile的单页AJAX加载。每个页面都是自己的文件 需要时,我会在页面上动态创建主页按钮。今天我只使用一个指向“index.html”的标记。有什么方法可以检查我的web应用程序jQueryMobile历史记录,找到历史上第一次加载index.html页面的地方,并调用window.history.back(-##);添加到页面,而不仅仅是添加到历史记录和导航 代码将是这样的,如果历史记录中没有index.html,我将只使用window.location.href访问页面 f
function
GoHome()
{
/* This is a function I don't know even exists, but it would find the first occurrence of index.html */
var togo = $mobile.urlHistory.find( 'index.html' )
var toback = $mobile.urlHistory.length -1 - togo;
if ( togo >= 0 )
window.history.back( -1 * toback )
else
$.mobile.changePage( '/index.html' )
}
如果历史记录是index.html=>profile.html=>photos.html
$.mobile.urlHistory.find('index.html')的神奇函数将返回0,历史长度将是3,因此我的计算将是window.history.back(-2)以返回index.html页面。如果find函数返回-1,那么就找不到它,我只需要执行一个changepage调用
谢谢
/Andy在阅读了一遍又一遍的阅读之后,我真的不知道我在读什么,我写了这个函数。不确定它是正确的还是最好的解决方案,甚至不确定它是否可以浓缩 用这个打电话
console.log( 'FindHome: ' + FindHome( ["", 'index.html'] ) );
它将在jQueryMobileUrlHistory.stack中从第一个条目搜索当前索引,并查看是否会找到索引页。从那里,我可以决定如果我想加载一个新页面或返回-xx到历史上已经存在的页面,该怎么做。这样的话,历史会有点干净
function
FindHome( _home )
{
var stk = $.mobile.urlHistory.stack;
var ai = $.mobile.urlHistory.activeIndex;
for ( var idx=0; idx <= ai; idx++ )
{
var obj = $.mobile.path.parseUrl( $.mobile.urlHistory.stack[idx].url );
if(typeof _home == "string")
{
if ( _home == obj.filename )
return( idx - ai );
}
else
{
for(var x in _home)
{
if ( _home[x] == obj.filename )
return( idx - ai );
}
}
}
return ( 0 );
}
函数
FindHome(_home)
{
var stk=$.mobile.urlHistory.stack;
var ai=$.mobile.urlHistory.activeIndex;
对于(变量idx=0;idx