Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to load page from the browser history ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 583
    Comment on it

    History go() method : The history object has the go() method which is used to load page from the browser history. You can choose specific url or index of the previous or next browsed page.


    Syntax of the go() method :

    1. history.go(number|URL)

    number|URL : Required. This parameter can have numeric value or a string. The numeric value refer the index of the URL in browser history, for example if you want to go 2 pages back then you can simply give go(-2) and to go next go(2). And you can also pass a URL string if find any matches in history then it will open that page.


    Example of history go() method : Here is the sample code to show how you can load previous and next page using JavaScript history.go() function.

    Sample1.html

    1. <!DOCTYPE html>
    2. <html>
    3. <body>
    4. <p>To go to the 2 pages back click the button "Go 2 pages back".</p>
    5. <button onclick="goToBack()">Go 2 pages back</button>
    6.  
    7. <script>
    8. function goToBack() {
    9. window.history.go(-2);
    10. }
    11. </script>
    12.  
    13. </body>
    14. </html>

    This sample code will take you to the 2 pages back from the history.


    Sample2.html

    1. <!DOCTYPE html>
    2. <html>
    3. <body>
    4. <p>To go to the next page click the button "Go To Next Page from URL history".</p>
    5. <button onclick="goToNext()">Go To Next Page from URL history</button>

    6.  
    7. <script>

    8. function goToNext() {
    9. window.history.go(1);
    10. }
    11. </script>

    12.  
    13. </body>

    14. </html>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: