因此,我正在为一个应用程序重写 UI,该应用程序当前通过 iframe 加载所有实际页面内容,并且只有一个包含菜单和其他信息的包装器。
我的问题是替换这些 iframe 并保留浏览器历史记录功能(后退/前进)的最佳方法是什么。
我一直在想的一些事情:
扩展基本模板(这似乎是一个好方法,但有些页面是用不同的模板语言编写的,所以工作量很大)
通过 jQuery 加载(我正在尝试使用 .load() 方法执行此操作,但似乎浏览器历史记录比我想象的要复杂)
=====更新=======
所以我正在尝试使用 jquery BBQ 和 queryparam 但我不确定我是否正确使用它不会改变 window.location
$(function(){
pageLoadAnimation('{{ framesource }}');
});
function pageLoad(url){
console.log(url);
$.param.querystring(window.location.href, 'p='+url , 2);
}
function pageLoadAnimation(url){
$('body').css('cursor','wait');
$('#mainframe').html('');
$('#page-load-wrap').slideDown();
$('#page-load-indicator').css('width','80%');
$.get(url,function(data){
console.log(data);
$('#page-load-indicator').css('width','100%');
$('#page-load-wrap').slideUp('slow',function(){
$('#mainframe').html(data);
});
$('body').css('cursor','default');
});
}
所以 FrameSource 是一个 jinja 变量,它通过 url 中名为 p 的参数设置。它在页面加载时被正确读取,但是当我尝试单击链接时没有任何反应。
示例链接
<a onclick="pageLoad('%2Fdashboard')">Overview</a>
控制台错误
Uncaught TypeError: Object function (a,b){var d=[],e=function(h,l) {l=c.isFunction(l)?l():l;d[d.length]=
encodeURIComponent(h)+"="+encodeURIComponent(l)};if(b===B)b=c.ajaxSettings.traditional; if(c.isArray(a)||a.jquery)c.each(a,function(){e(this.name,this.value)});else for(var f in a)da(f,a[f],b,e);return d.join("&").replace(tb,"+")} has no method 'querystring'
让后退按钮在没有插件但没有前进的情况下工作:
改变:
$.param.querystring(window.location.href, 'p='+url , 2);
至:
window.location = window.location.origin+window.location.pathname+'?p='+url;