[英]Back Button not work when load page using history.pushState in JS
I am trying to load a page via ajax with history.pushState
and page load successfully, but the back button does not work in this case.我正在尝试通过 ajax 加载页面,并成功加载history.pushState
和页面,但在这种情况下后退按钮不起作用。 Please check my code below:请在下面检查我的代码:
function processAjaxData(response, urlPath){
document.write(response)
document.title = '';
window.history.pushState({"html":response,"pageTitle":''},"", urlPath);
}
$('#apply_loader').click(function(e){
var nextPage = $(this).attr('href');
$.get(nextPage, // url
function (data, textStatus, jqXHR) { // success callback
processAjaxData(data,nextPage);
}
);
});
I am trying to use popstate
below to identify a back button click.我正在尝试使用下面的popstate
来识别后退按钮单击。
$(window).on('popstate', function(event) {
console.log('asd');
location.reload();
});
Maybe too late, but perhaps this will fix the problem:也许为时已晚,但也许这会解决问题:
Instead of location.reload(), try:而不是 location.reload(),尝试:
window.location = location.href
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.