Code2care : TechZone Apps & Tutorials

Loading previous page using html button using javascript



Web browsers have a back button that lets you go back to the previous page you just visited. If you want this functionality to be performed using a button in HTML you need to make use of history.back() function available in window object.

To demonstrate, lets create a html page with a button and call getPrevPage() function onClick of it. Create a the function in head section script block.

<!DOCTYPE html>
<html>
<head>
<script>
function getPrevPage() {

     //gets to the previous loaded page
     window.history.back();

}
</script>
</head>

<body>

<input type="button" value="Back" onclick="getPrevPage()">

</body>
</html>


Similarly we have window.history.forward() that works just as the forward button on the web browsers. Lets create an example with both back and forward button implementation.

<!DOCTYPE html>
<html>
<head>
<title>Previous and Next Page button implementation using Javascript</title>
<script>
function getPrevPage() {

     //gets to the previous loaded page
     window.history.back();

}

function getNextPage() {

     //gets to the next loaded page
     window.history.forward();

}
</script>
</head>

<body>

<input type="button" value="Load Prev Page" onclick="getPrevPage()">
<input type="button" value="Load Next Page" onclick="getNextPage()">
</body>
</html>












Top




Posts related to javascript.


1. Top 15 Programming Languages to learn 2014-2015

2. How to detect Browser and Operating System Name and Version using javaScript

3. How to make jsfiddle bootstrap ready

4. Detect if Cookies are enabled using javascript

5. How to get UTC (GMT) using javascript

6. Add Animated Scrolling to Html Page Title Script

7. Loading previous page using html button using javascript

8. Get Device Screen Width and Height using javaScript

9. Digital clock example using javaScript with Source code

    more...






Popular tags
android
x 175
eclipse
x 29
notepadplusplus
x 20
macosx
x 14
sharepoint
x 14
html
x 14
mac
x 13
androidstudio
x 11




1000+ C Programs     PHP Tutorial     JSON Tutorial     Swift Tutorial     India Pinocdes     About Us     Privacy Policy


Code2care © 2012-17