Can JavaScript intercept and cancel browser buttons back and forth?

We are writing a web application to act as a control panel for our back end, we use only JavaScript. All DOM elements are created dynamically, without static HTML at all.

We have an interface like module / plugin, a module is a set of β€œviews” - a view is essentially a function that contains the initialize method, which takes a div argument, so it knows where to draw itself.

As the user views the views, we save the history of where they were and where they are, etc., so we can provide reverse / forward navigation between the views, as well as save the state of the views while they are moving.

We provide a breading track, as well as back and forth buttons. What I would also like to do is to intercept the browser buttons back / forward so that we can intercept clicks and redefine them so that it views the history that we support. When they get to the first page of the story that we support, we would certainly not redefine and allow them to move from our site.

Is there a general way to do this? Or do browsers explicitly prevent such things?

thanks

+4
source share
1 answer

Use the extended jQuery-bbq plugin for Ben Alman: http://benalman.com/projects/jquery-bbq-plugin/ , which provides a hash cross browser that is used in conjunction with the back / forward buttons.

+11
source

Source: https://habr.com/ru/post/1337627/


All Articles