Reputation: 3277
Is it possible to change the address of the back button in the browser? For example I am in this page:
I submit a form and it returns this address:
http://website.com/page3.php?ok=ok
After which when I go to another page, for example
and click the back button, it goes back to the page with $_GET variables on it.I want it that when I click the back button of the browser to go here:
Is it possible for the back button (of the browser) that everytime I click it whenever I just came from that specific page with variables, it wont get the variables as well?
Upvotes: 5
Views: 1795
Reputation: 1696
You can alter locations with window.location.replace(), or implement deeplinking in your URLs if it's a post-hash route:
Difference between window.location.href, window.location.replace and window.location.assign
http://en.wikipedia.org/wiki/Deep_linking
Cheers,
Andrew
Upvotes: 0
Reputation: 11933
One method would be to do the form post request using AJAX.
Another one would be to add tokens to your forms and check them server side to redirect using header() if they don't exist. Eg :
<?php
session_start();
if(isset($_GET['ok'])){
if(isset($_SESSION['form_page3_token'])){
$_SESSION['form_page3_token'] = null;
//first request : do your stuff
}else{
//repost (F5 or Back in the browser => redirect to origin form)
header('Location: http://www.website.com/page3.php');
}
}else{
$_SESSION['form_page3_token'] = session_id();
//here the code to show the form
}
?>
Upvotes: 1
Reputation: 7240
I think you can set a session variable on your form in http://website.com/page3.php. and then unset it once the submission is done in http://website.com/page3.php?ok=ok.
and each time the page with the variable in the url is loaded, check immediately for the submission session variable to see if you are redirected to the page from the form page. and if not, redirect you back to the page3.page.
I hope I made myself clear enough!
Upvotes: 2
Reputation: 141
You can't override the behaviour that if a user follows a link to your page, clicking Back will take them off it again.
Upvotes: 0
Reputation: 182
This is not possible you can hack something together by using pushState and playing with the browser history
Upvotes: 1