Go Back to Previous Page

前端 未结 11 653
悲哀的现实
悲哀的现实 2020-12-02 07:20

I am using a form to \"Rate\" a page. This form \"posts\" data to a php script elsewhere. I simply want to display a link after the form is processed which will bring the us

相关标签:
11条回答
  • 2020-12-02 08:00

    If your web-server correctly redirects you to a new page after you made a post, the regular "back" button on the browser will work. Or the "history.go(-1)" in javascript. This will produce a filled out form.

    However, if the server just returns new content without redirecting - then history.go(-1) is not going to help you. At that point you have lost your form.

    If you just want to simply go back to the previous url - just link to it with an A HREF tag. That will show you an empty form.

    0 讨论(0)
  • 2020-12-02 08:01

    You can use a link to invoke history.go(-1) in Javascript, which is essentially equivalent to clicking the Back button. Ideally, however, it'd be better to just create a link back to the URL from whence the user was posted to the form - that way the proper "flow" of history is preserved and the user doesn't wonder why they have something to click "Forward" to which is actually just submitting the form again.

    0 讨论(0)
  • 2020-12-02 08:09

    Try this:

    $previous = "javascript:history.go(-1)";
    if(isset($_SERVER['HTTP_REFERER'])) {
        $previous = $_SERVER['HTTP_REFERER'];
    }
    

    in html:

    <a href="<?= $previous ?>">Back</a>
    

    The JavaScript code is initialize as fallback for HTTP_REFERER variable sometimes not work.

    0 讨论(0)
  • 2020-12-02 08:10

    history.go(-1) this is a possible solution to the problem but it does not work in incognito mode as history is not maintained by the browser in this mode.

    0 讨论(0)
  • 2020-12-02 08:11

    ... By looking at Facebook code ... I found this

    0 讨论(0)
  • 2020-12-02 08:12

    Depends what it is that you're trying to do it with. You could use something like this:

    echo "<a href=\"javascript:history.go(-1)\">GO BACK</a>";
    

    That's the simplest option. The other poster is right about having a proper flow of history but this is an example for you.

    Just edited, orig version wasn't indented and looked like nothing. ;)

    0 讨论(0)
提交回复
热议问题