get back to previous page

前端 未结 6 1073
刺人心
刺人心 2020-12-16 18:41

just i want to make back button in my site. once i click the button it need to take the url in to previous page. how can i make this using jquery?

相关标签:
6条回答
  • 2020-12-16 18:50
    <button type="button" onclick="history.back();">Back</button>
    
    0 讨论(0)
  • 2020-12-16 18:52

    Try this: am using materialise css.

    <button id="back_btn" class="btn waves-effect waves-light"  name="action">Back<i class="material-icons left">chevron_left</i>
    </button>
    

    In your jquery script file add

    $("#back_btn").click(function (){
      window.history.back();
    });
    

    within the document ready function.

    0 讨论(0)
  • 2020-12-16 18:56

    For JQM, this works!

    $(document).ready(function(){
        $('.backLink').click(function(){
            parent.history.back();
            return false;
        });
    });
    
    0 讨论(0)
  • 2020-12-16 19:05

    the answer by wRAR is correct, you can use history.back or history.go(-1). However, if you are using ajax, you might need a bit more than that.

    Stephen Walter has a nice article on how to use jQuery, ASP.NET, and Browser History which basically describes how to save and restore the application state yourself. I recommend you give a read.

    Elijah Manor(co-host of the Official jQuery Podcast) has also written a nice article about this topic.

    I hope this helps -D

    0 讨论(0)
  • 2020-12-16 19:07

    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-16 19:08

    This is what I have successfully used in one of my recent projects:

    <script>
        function goBack() {
           window.history.back();
        }
    </script>
    <a href="#" onclick="goBack()" class="btn-event-show-video">
         Return to Stand
    </a>
    
    0 讨论(0)
提交回复
热议问题