I want to disallow the visitor go back in browser, I tried the code here (How to disable back button in browser using javascript) and works well, but I want to make somenthing more useful for my application. I want to change the back url.
So, if the back URL is mywebsite/admin/add_new_article.php I want to change the back URL to mywebsite/admin/index.php
Thank you all!
I want to disallow the visitor go back in browser, I tried the code here (How to disable back button in browser using javascript) and works well, but I want to make somenthing more useful for my application. I want to change the back url.
So, if the back URL is mywebsite.com/admin/add_new_article.php I want to change the back URL to mywebsite.com/admin/index.php
Thank you all!
Share Improve this question edited May 23, 2017 at 12:34 CommunityBot 11 silver badge asked May 29, 2015 at 10:07 ITChristianITChristian 11.3k14 gold badges53 silver badges93 bronze badges 3- 3 Why? And I'm fairly certain that this isn't possible either, and shouldn't be. Let's consider this, a user visits the site, unsuspecting and innocent, he sees that the site he visited is "bad" and wants to go back to his google search, WHAM, the user is now on a infected site and so is his computer now. – Epodax Commented May 29, 2015 at 10:10
- I think that this would be very useful for PWAs: please vote this feature request on WICG. Despite the comments, it can also be developed in a secure way to prevent abuses. This feature is needed to align PWA capabilities to native apps! – collimarco Commented May 31, 2020 at 18:34
- @Epodax scenario: if a mobile viewer visits page A, he gets redirected to the mobile version of page A. So if he presses back he will be going back to page A desktop version instead of the actual page he came from and be directed again to page A mobile. Endless loop. Viewer cannot go back to where he came from. – larry909 Commented Jan 26, 2022 at 10:20
1 Answer
Reset to default 18<script type="text/javascript">
history.pushState(null, null, '<?php echo $_SERVER["REQUEST_URI"]; ?>');
window.addEventListener('popstate', function(event) {
window.location.assign("http://www.yoururl.com/");
});
</script>
Hope it helps!