How to stop people using the back button of the browser after they left my site so that they could not return?

I really need this as a security feature - the theme of my site is sensitive (domestic violence) - we have a security zone on the site, and if you click, a person will be taken out of the site to a "safe" site.

As soon as they click on this area, I would like them not to return within the designated period of time (say, 1 hour), so if the occupant entered the room, you could leave the site, and even if they hit on the back the button would not be obvious which site they were looking at.

Ideas ??

+6
source share
2 answers

You can always capture the back button event and send the user a random β€œsecure” URL using something like:

window.onbeforeunload = function () { location.replace('http://www.bbc.co.uk'); return "This session is expired and the history altered."; } 

Inside the function block, you can also simply set a cookie called "noreturn", which, whenever any pages on your site are checked, can then be redirected each time to the "safe" site for the next hour.

There is a decent article on all aspects of managing the back button and the user's browser history here ;

+4
source

See the following anwser from Scott Hanselman. You can also put a random key in the query string and check the value for the list and perform the necessary actions if this key is no longer in your authorized users.

0
source

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


All Articles