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 f开发者_StackOverflow中文版unction (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
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.
精彩评论