Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the back button URL in browser

Tags:

javascript

php

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!

like image 591
MM PP Avatar asked May 29 '15 10:05

MM PP


People also ask

How do you back into a URL?

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.

How do I get my back button to work in Ajax?

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 .

What is Back Button in browser?

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.


1 Answers

<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!

like image 122
NETCreator Hosting - WebDesign Avatar answered Oct 06 '22 00:10

NETCreator Hosting - WebDesign