How to Use the javascript history object (history) (implement browser forward and backward)

Source: Internet
Author: User

The window. history Object does not use the window prefix when writing. To protect user privacy, the methods for accessing this object by JavaScript are limited.

Method:

History. back ()-load the previous URL in the history list, which is the same as clicking the forward button in the browser.
History. forward ()-load the next URL in the history list, which is the same as clicking the forward button in the browser.

Instance:

Copy codeThe Code is as follows:
<Html>
<Button name = "back" value = "back" onclick = "goBack ()"> back </button>
<Button name = "forward" value = "forward" onclick = "goForward ()"> forward </button>
<Script type = "text/javascript">
Function goBack (){
History. back ();
}
Function goForward (){
History. forward ();
}
</Script>
</Html>

Other methods:

Copy codeThe Code is as follows:
History. go (0); // refresh the current page
// The following information must be recorded in the browser, otherwise it will not work.
History. go (1); // Previous Page
History. go (-1); // return a page
History. go (-2); // two back pages
History. length; // number of historical records contained in the current window

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.