Google News
logo
Javascript History Object
The JavaScript history object represents an array of URLs visited by the user. By using this object, you can load previous, forward or any particular page. The history object has the following features:
Hisory Object Properties :
Property Description
length The length of the history URLs.
current Current entry in the object
Hisory Object Methods :
Method Description
forward() Next element in the URL History list.
back() Previous element in the URL History list.
go() loads the given page number.
Example Program :
<html>
<head>
<title>JavaScript History Object</title>
 
<script type="text/javascript">
function myHistory()
{
var historyCount = history.length;
alert("Hi, you have visited " + historyCount + " web pages.");
}
function funBackward()
{
window.history.back()
}
function funForward()
{
window.history.forward()
}
function funGo()
{
window.history.go(1)
}
</script>
 
</head>
<body>
 
<h3>JavaScript History Object Example</h3>
<form>
<input type="button" name="history" value="My History" onClick="myHistory()">
<input type="button" id="btgo" value="Go to Next Link" onClick="funGo();">
<input type="button" id="btfo" value="Forward" onClick="funForward();">
<input type="button" id="btba" value="Backward" onClick="funBackward();">
</form>
 
</body>
</html><html>
<head>
<title>JavaScript History Object</title>
 
<script type="text/javascript">
function myHistory()
{
var historyCount = history.length;
alert("Hi, you have visited " + historyCount + " web pages.");
}
function funBackward()
{
window.history.back()
}
function funForward()
{
window.history.forward()
}
function funGo()
{
window.history.go(1)
}
</script>
 
</head>
<body>
 
<h3>JavaScript History Object Example</h3>
<form>
<input type="button" name="history" value="My History" onClick="myHistory()">
<input type="button" id="btgo" value="Go to Next Link" onClick="funGo();">
<input type="button" id="btfo" value="Forward" onClick="funForward();">
<input type="button" id="btba" value="Backward" onClick="funBackward();">
</form>
 
</body>
</html>
Output :