JS:使用“window.location”重定向不在Firefox中保存历史记录 [英] JS: Redirecting with 'window.location' not saving history in Firefox

查看:328
本文介绍了JS:使用“window.location”重定向不在Firefox中保存历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重定向而不会丢失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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆