Javascript: detecting when a page has been moved back to

Suppose I have a page open in a browser, and I go to my address bar and enter another page. Then I click the back button to go to the original page. I would like to write Javascript code that can detect this script and respond to it.

As far as I can tell, not a single event ready , onload , nor any embedded Javascript on the page itself is re-executed in this script. Is there anything else I can do?

Cross browser support is important here. JQuery-based solutions are preferred but not required.

Edit for clarity: the navigation I assume is Page A → Page B → back to page A, where I assume that page B may or may not be under my control.

+6
source share
3 answers

http://benalman.com/projects/jquery-bbq-plugin/ seems good if you are considering a jQuery plugin.

+1
source

You should try to provide the user with a cookie on both pages, go to the page and the page itself, with dates and times, and compare whether they are closed or show that it was on one page, on the other, and then redirected.

Another option is to provide the user with a cookie when they are redirected.

0
source

In Firefox, you can check the DomContentLoaded event. A cross-browser solution requires a bit more work:

http://dean.edwards.name/weblog/2005/09/busted/

0
source

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


All Articles