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!
In a web browser, the built-in JavaScript object window has an object called history containing the URLs a user has visited in their current browser window. You can use the history. back() method to tell the browser to go back to the user's previous page.
To make back button work with AJAX, catch onpopstate event. This handler is triggered that changes the url when back button is clicked. On this event, send AJAX to location. href .
A back button in the browser lets you back-up to the copies of pages you visited previously. The web browser's back and next buttons work well with web sites that provide information that changes infrequently, such as news and shopping web sites.
<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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With