JS:使用“window.location”重定向不在Firefox中保存历史记录 [英] JS: Redirecting with 'window.location' not saving history in Firefox
问题描述
我已经使用了下一个没有成功:
window.location =http://example.com;
window.location.href =http://example.com;
window.location.assign(http://example.com);
还尝试使用'document'而不是'window'。
我得到重定向,但历史不会从浏览器中添加(或删除)
任何想法!?
注意:我不是直接调用这个函数,而是在向服务器发送一个成功的jQuery Ajax请求之后调用它:
$。ajax({
type:POST,
...
success:function(data){},
});
变量数据包含JS重定向函数( window.location.href = http://example.com
)
设计: http://warpspire.com/posts/url-design/ 特别是标题为一切都应该有一个网址部分。基本上你会想使用history.pushState函数来添加新的url到浏览器的历史记录。您也可以查看类似的stackoverflow帖子:在AJAX调用更新网址?或在浏览器中更改URL而不使用JavaScript加载新页面
I'm trying to redirect without losing the history in Firefox. I have used the next without success:
window.location = "http://example.com";
window.location.href = "http://example.com";
window.location.assign("http://example.com");
Also tried using 'document' instead of 'window'.
I get redirected, but the history is not added (or deleted) from the browser
Any ideas!?
Note: I'm not calling this function directly, I'm calling it after a succesfull jQuery Ajax request to the server:
$.ajax({
type: "POST",
...
success: function (data) {},
});
the variable data contains the JS redirect function (window.location.href = "http://example.com"
)
You might check out this article on URL Design: http://warpspire.com/posts/url-design/ In particular the section titled "Everything should have a url". Basically you will want to use the history.pushState function to add the new url to the browser history. You can check out similar stackoverflow post as well: Update URL on AJAX call? or Change the URL in the browser without loading the new page using JavaScript
这篇关于JS:使用“window.location”重定向不在Firefox中保存历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!