Home  >  Article  >  Web Front-end  >  How to use javascript history object (history record) (implementing browser forward and backward)_Basic knowledge

How to use javascript history object (history record) (implementing browser forward and backward)_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:05:042084browse

The window.history object does not need to use the window prefix when writing. To protect user privacy, JavaScript's methods of accessing this object are restricted.

Method:

history.back() - Loads the previous URL in the history list, this is the same as clicking the forward button in the browser
history.forward() - Loads the next URL in the history list, this is the same as clicking the forward button in the browser Clicking the forward button in the browser is the same

Example:

Copy code The code is as follows:



Copy code The code is as follows: history.go(0);//Refresh the current page
//The following must have a history record in the browser, otherwise it will not be effective.
history.go(1);//Go forward one page
history.go(-1);/ /Go back one page
history.go(-2);//Go back two pages
history.length;//Number of history records contained in the current window


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn