0

How I can modify last URL of browser history ?

Example:

  1. If currently user is on a specific page or URL, say: /page3
  2. Because of some functionality (error handled), the user goes to /page1.
  3. In the context of page /page1, if user clicks on browser's back button, I want to redirect the user to /page2 instead of /page3.

How can I achieve this using JavaScript, jQuery or AngularJS?

Rohan Büchner
  • 5,333
  • 4
  • 62
  • 106
Arvind Kushwaha
  • 759
  • 2
  • 10
  • 18

1 Answers1

1

in http://example.com/page3 add the few codes from the following link... this is not the exact answer... but looks like it will help you

function goBack() {
    window.location.hash = window.location.lasthash[window.location.lasthash.length-1];
    //blah blah blah
    window.location.lasthash.pop();
}

window.onbeforeunload = function (evt) {
    goBack();
    history.pushState("http://example.com/page2", document.title, window.location.pathname);
//  var message = 'Are you sure you want to leave?';
//  if (typeof evt == 'undefined') {
//    evt = window.event;
//  }
//  if (evt) {
//    evt.returnValue = message;
//  }
//  return message;
  return "Back";
}

For more details please refer this

https://stackoverflow.com/a/25806609/6082645

https://stackoverflow.com/a/2008838/6082645

Community
  • 1
  • 1
jafarbtech
  • 6,842
  • 1
  • 36
  • 55