Javascript:window.history.go (-1) What does that mean?

Source: Internet
Author: User

Javascript:window.history.go (-1) What does that mean?

history is a collection of URLs (simply called URLs) of the pages you've browsed, which is the historical record in your browser. It is a built-in object in JS, just like document, it has its own method, go is one of them.

The parameter of this method is a number that specifies the index of the URL to locate relative to the current page URL location. The current URL is labeled 0, so Window.history.go (-1) is going to be positioned relative to the page labeled 1 on the current page, which is the page you just visited .

Let me give you an example:
you visit Baidu page in the Address bar (http://www.baidu.com), then the history of the address added to its collection, and will be calibrated to 0.
through the search, you visited the Sina page (http://www.sina.cn), the browser also put this site in the history, and the site of the next calibration of 0, The previous visit to the Baidu page subscript relative to this visit Sina page becomes -1.
If you then open the netease page through the news link (http://www.163.com), the browser will be the same as on the NetEase in the history, subscript 0, and netease before a visit to the page Sina, in the history of the subscript has become-1, the same as Baidu's subscript becomes -2.

At this time, you through the Window.history.go (-1) statement, you can make the page to the current page of the previous page, that is, Sina , if you are using Window.history.go (-2), you can directly reach the Baidu page.

In a word, this code is just like the back button on your browser .

Javascript:window.history.go (-1) What does that mean?

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.