I need to disable the back button of browser in my single page application. I tried using methods like onhashchange or window.history.forward but they don't work (reason may be that url doesn't get changed here) Please help! Thanks.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
If you're using AngularJS, the following code should do the trick. You have to add this code to app.js file or file where you inject all your dependencies
I dont think disabling the back button will really work. So many reasons for same but have look at this. Your best solution will be warn the user using
You technically cannot disable the Back button on someone's browser, however, you can make it so that the button isn't available or continues to load the same page.
You can check it here Disabling the Back Button
You can redirect same page on click of back button, your page will get refreshed but you will be on the same page every time
I work in AngularJS building a Single Page App and I wanted to disable or prevent the back button of the browser, because my app has buttons and anchors for all navegation into my app.
I searched and test many codes, and this is the easy to prevent the back button of browsers and the following code worked for me.
When the history detects the first history.back()
is executed, then after this moment any back or forward in history are detected for onpopstate event.
i think the "onpopstate" dont work if the user persist click
just use
or if u like to warning user