How to write the code for the back button?

前端 未结 7 543
梦毁少年i
梦毁少年i 2020-12-23 17:43

I have a php code here and I would like to create a "back" href to get me back to where I was before. Here\'s what I have:



        
相关标签:
7条回答
  • 2020-12-23 18:07
    <a href="javascript:history.back(1)">Back</a>
    

    this one (by Eiko) is perfect, use css to make a button of <a>... eg you can use this css class in <a> as `

    <a class=".back_button" href="javascript:history.back(1)">Back</a>`
    
    .back_button {
    display:block;
    width:100px;
    height:30px;
    text-align:center;
    background-color:yellow;
    border:1px solid #000000;
    }
    
    0 讨论(0)
  • 2020-12-23 18:12

    If you want to do it (what I think you are trying right now) then replace this line

    <input type="submit" <a href="#" onclick="history.back();">"Back"</a>
    

    with this

    <button type="button" onclick="history.back();">Back</button>
    

    If you don't want to rely on JavaScript then you could get the HTTP_REFERER variable an then provide it in a link like this:

    <a href="<?php echo $_SERVER['HTTP_REFERER'] ?>">Back</a>
    
    0 讨论(0)
  • 2020-12-23 18:14
    <button onclick="history.go(-1);">Back </button>
    
    0 讨论(0)
  • 2020-12-23 18:15

    In my application,above javascript function didnt work,because i had many procrosses inside one page.so following code worked for me hope it helps you guys.

      function redirection()
            {
               <?php $send=$_SERVER['HTTP_REFERER'];?> 
                var redirect_to="<?php echo $send;?>";             
                window.location = redirect_to;
    
            }
    
    0 讨论(0)
  • 2020-12-23 18:16
    <input type="submit" <a href="#" onclick="history.back();">"Back"</a>
    

    Is invalid HTML due to the unclosed input element.

    <a href="#" onclick="history.back(1);">"Back"</a>
    

    is enough

    0 讨论(0)
  • 2020-12-23 18:18

    You need to tell the browser you are using javascript:

    <a href="javascript:history.back(1)">Back</a> 
    

    Also, your input element seems out of place in your code.

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