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?

2

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.