0

I have a button on a view, which on submit directs the user's browser back to the previous page using window.history.go(-1);. This is necessary for us to maintain session data to display the previous view correctly.

My question is, is it possible for us to determine whether there is any browser history using jQuery so that if there is none we can instead redirect the user with

window.location = "/Transaction/Index";

to the correct page?

Thanks in advance!

George
  • 36,413
  • 9
  • 66
  • 103
Nick Chambers
  • 181
  • 1
  • 13

1 Answers1

0

From MDN:

HTML5 introduced the history.pushState() and history.replaceState() methods, which allow you to add and modify history entries, respectively. These methods work in conjunction with the window.onpopstate event.

Using history.pushState() changes the referrer that gets used in the HTTP header for XMLHttpRequest objects created after you change the state. The referrer will be the URL of the document whose window is this at the time of creation of the XMLHttpRequest object.

Example:

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
Pang
  • 9,564
  • 146
  • 81
  • 122
Rohit
  • 93
  • 1
  • 6