【发布时间】:2012-03-21 00:21:59
【问题描述】:
我在 Jquery Mobile 中使用嵌套页面:
看起来像这样:
// wrap page
<div data-role="page" id="wrap">
// panel
<div data-role="panel" data-id="popover">
// nested pages
<div data-role="page" id="nested1"></div>
<div data-role="page" id="nested2"></div>
</div>
</div>
在转换时,我正在切换 $.mobile.pageContainers 以将嵌套页面加载到面板中而不是加载到正文中(默认 JQM),如下所示:
$.mobile.changePage( page-to-be-loaded, {
// previous page in panel
fromPage:from,
// update the URL with the nested page hash
changeHash:hashChange,
// target panel
pageContainer: $('div:jqmData(id="popover")')
});
这一切都按预期工作 = 当我在面板中加载嵌套页面时,URL 更新为
http://some.com#nested1/2/3...
我的问题在于“清理”URL,当我离开包装页面并完全进入一个新的 JQM 页面时
在这种情况下,URL 停留在最后一个嵌套页面,当我需要告诉 JQM 我实际上仍在包装页面上时(无论哪个嵌套页面仍在 URL 中)。
问题: 因此,我正在寻找一种将 URL 更新为正确值的方法,或者将页面参数设置为“出厂默认值”的好方法,这样 JQM 永远不会知道我在嵌套页面上做了任何面板转换。
我试过了:
// 1. location hash - doesn't work
window.location.hash = ""
// 2. ReplaceState - breaks on non-push-state browsers
// on pageinit store defaults
var $myState = {};
$myState.title = document.title;
$myState.url = location.protocol + '//' + location.host + location.pathname;
page.data("rememberState", $myState )
// before leaving the wrap page
var rem = $('#wrap.ui-page-active').data("rememberState");
if (rem && typeof rem != 'undefined') {
history.replaceState('null',rem.title,rem.url);
}
// 3. Reload the page when hiding the panel - crashes my browser :-)
$.mobile.changePage('#wrap', {
allowSamePageTransition: true,
changeHash:true,
transition:none
});
由于我已经远离 JQM 路径,我只是在寻找提示。感谢您的任何指示!
【问题讨论】:
标签: javascript jquery url jquery-mobile pushstate