admin管理员组

文章数量:1431391

Is it possible to change the address of the back button in the browser? For example I am in this page:

.php

I submit a form and it returns this address:

.php?ok=ok

After which when I go to another page, for example

.html

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:

.php

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?

Is it possible to change the address of the back button in the browser? For example I am in this page:

http://website./page3.php

I submit a form and it returns this address:

http://website./page3.php?ok=ok

After which when I go to another page, for example

http://website./blog.html

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:

http://website./page3.php

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?

Share Improve this question asked Feb 27, 2014 at 4:13 marchemikemarchemike 3,28713 gold badges60 silver badges99 bronze badges 1
  • May be help to you : bstavroulakis./blog/web/overriding-the-browsers-back-button – Butani Vijay Commented Feb 27, 2014 at 4:26
Add a ment  | 

5 Answers 5

Reset to default 2

I think you can set a session variable on your form in http://website./page3.php. and then unset it once the submission is done in http://website./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!

This is not possible you can hack something together by using pushState and playing with the browser history

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./page3.php');
        }
    }else{
         $_SESSION['form_page3_token'] = session_id();
         //here the code to show the form
    }
?>

You can't override the behaviour that if a user follows a link to your page, clicking Back will take them off it again.

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/wiki/Deep_linking

Cheers,

Andrew

本文标签: javascriptChange back button functionality in browser using jQueryStack Overflow