我试图在不丢失 Firefox 历史记录的情况下进行重定向。 我用了下没有成功:
window.location = "http://example.com";
window.location.href = "http://example.com";
window.location.assign("http://example.com");
还尝试使用“文档”而不是“窗口”。
我被重定向了,但是浏览器没有添加(或删除)历史记录
任何想法!?
注意:我没有直接调用这个函数,我是在向服务器成功发出 jQuery Ajax 请求后调用它:
$.ajax({
type: "POST",
...
success: function (data) {},
});
变量数据包含JS重定向函数(window.location.href = "http://example.com"
)
最佳答案
您可以查看这篇关于 URL 设计的文章:http://warpspire.com/posts/url-design/特别是标题为“Everything should have a url”的部分。基本上你会想要使用 history.pushState 函数将新的 url 添加到浏览器历史记录中。您也可以查看类似的 stackoverflow 帖子:Update URL on AJAX call?或 Change the URL in the browser without loading the new page using JavaScript
关于javascript - JS : Redirecting with 'window.location' not saving history in Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5018698/