0

I am using angularJS in my SPA. I want to disable the default action of browser back button/android back button in my webapp and create custom actions for the same.

Example case: I have a signup page where user entries are saved as scope variables before submitting the form. An amazing fullscreen form lets user select the location, having a back button to hide the form (just in case). As a bad UX, whenever the user presses back button in mobile or browser, page is redirected to previous page in location.history. Also, location.history.forward() method reinitializes the controller, thus having user to fill everything again.

What could be the best possible working solution in given constraints?

No external libraries please

1 Answer 1

0

maybe this could help you Control or Disable Browser Back Button with Javascript or AngularJS

or

window.onpopstate = function (e) { window.history.forward(1); }

When the history detects the first history.back()

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

1 Comment

On history.forward(), the controllers would be reinitialized. I wouldn't find it to be the most ideal way. I have found something alien in the $routeProvider documentation - reloadOnSearch property. Digging about it. Will update if that works. Thanks for help! Update: never mind the italics, misinterpreted in first read!! Duh!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.