3

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")

Jonathan
  • 8,146
  • 20
  • 64
  • 100
  • The chosen answer, while surely good advice, doesn't solve the problem posed in this question. This one does, however http://stackoverflow.com/questions/864633/assigning-to-document-location-href-without-clobbering-history – numbers1311407 Sep 12 '11 at 22:59

2 Answers2

2

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

Community
  • 1
  • 1
scrappedcola
  • 10,021
  • 1
  • 28
  • 41
-1

If you redirect within 15 seconds then Firefox won't save the previous page in history, because otherwise clicking back would display the previous page for no more than 15 seconds before it would redirect again, thereby serving only to annoy the user.

Neil
  • 50,855
  • 8
  • 54
  • 69