Go Back to Previous Page

前端 未结 11 654
悲哀的现实
悲哀的现实 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:13

    we can navigate to previous page by use any of below. 1) window.location.href="give url you want to go"; or 2) window.history.back(); or 3) window.history.go(-1); or 4) window.history.back(-1);

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

    You specifically asked for JS solutions, but in the event that someone visits your form with JS disabled a PHP backup is always nice:

    when the form loads grab the previous page address via something like $previous = $_SERVER['HTTP_REFERER']; and then set that as a <input type="hidden" value="$previous" /> in your form. When you process your form with the script you can grab that value and stick it in the header("Location:___") or stick the address directly into a link to send them back where they came from

    No JS, pretty simple, and you can structure it so that it's only handled if the client doesn't have JS enabled.

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

    I think button onclick="history.back();" is one way to solve the problem. But it might not work in the following cases.

    1. If the page gets refreshed or reloaded.

    2. If the user opens the link in a new page.

    To overcome these, the following code could be used if you know which page you have to return to. E.g. If you have a no of links on one page and the back button is to be used to return to that page.

    <input type="button" onclick="document.location.href='filename';" value="Back" name="button" class="btn">
    
    0 讨论(0)
  • 2020-12-02 08:21

    Like this:

    <?php
    
        if (isset($_SERVER["HTTP_REFERER"])) {
            header("Location: " . $_SERVER["HTTP_REFERER"]);
        }
    
    ?>
    
    0 讨论(0)
  • 2020-12-02 08:21

    We can show a back button using html code in our pages which can take the browser window to the previous page. This page will have a button or a link and by clicking it browser will return to previous page. This can be done by using html or by using JavaScript in the client side.

    Here is the code of this button

    <INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);">
    

    Using JavaScript

    We can use JavaScript to create a link to take us back to previous or history page. Here is the code to move back the browser using client side JavaScript.

    <a href = "javascript:history.back()">Back to previous page</a>
    
    0 讨论(0)
提交回复
热议问题