Thursday 24 November 2011

History Object


·         History object is actually a javascript object.
·       The history object is automatically created by the javascript runtime engine and consist of  array of urls. Which is an array of history item having details of the url’s visited from within that window.
·   The history object is part of window object and is access through the window.history property.

Ø       History object method

1.length

·         Returns the number of element in the history list.

Syntax :  history.length

Example

<html>
          <head>
                   <script language="javascript">
                             document.write(history.length);
</script>
          </head>
     </html>

Ø       History object method

·         back()
·         forward()
·         go()

1.back()

·         This method loads the previous url in the history list.
·         This is same as clicking the back button and history.go(-1).

Syntax :  history.back()

Example

<html>
          <head>
                   <script language="javascript">
                             function goback()
                             {
                                      window.history.back();
                             }
</script>
          </head>
<body>
                   <input type="button" value="Click Here" onclick="goback();" />
          </body>       
</html>

2.forward()

·         This method loads the next url in the history list.
·         This is same as clicking the forward button.

Syntax :  history.forward()

Example

<html>
          <head>
                   <script language="javascript">
                             function goforward()
                             {
                                      window.history.forward();
                             }
</script>
          </head>
<body>
                   <input type="button" value="Click Here" onclick="goforward();" />         </body>
     </html>

3.go()

·         This method loads a specific page in the history list.

Syntax :  history.go(number)

Example

<html>
          <head>
                   <script language="javascript">
                             function getdata()
                             {
                                      window.history.go(-1);
                             }
</script>
          </head>
<body>
                   <input type="button" value="Click Here" onclick="getdata();" />  </body>
     </html>

Posted By : Hemangi Zala

No comments:

Post a Comment