繁体   English   中英

在 JS 中使用 history.pushState 加载页面时后退按钮不起作用

[英]Back Button not work when load page using history.pushState in JS

我正在尝试通过 ajax 加载页面,并成功加载history.pushState和页面,但在这种情况下后退按钮不起作用。 请在下面检查我的代码:

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);
      }
    );
});

我正在尝试使用下面的popstate来识别后退按钮单击。

  $(window).on('popstate', function(event) {
    console.log('asd');
     location.reload();
  });

也许为时已晚,但也许这会解决问题:

而不是 location.reload(),尝试:

window.location = location.href

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM