javascript realize the browser address bar backward movement ban

This way, you can eliminate all back in action. Backward operation including a keyboard, mouse gestures produced.
Principle: the use popstate events and pushState method, popstate html5 is a new event, it will trigger a change in the browser history, generally can be understood, when the user clicks the back button, triggers popstate event.

For example, the code below:


```
<script language="javascript">
//防止页面后退
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
          history.pushState(null, null, document.URL);
});
</script>
```

Guess you like

Origin www.cnblogs.com/wkyuan/p/11313657.html