Home > Web Front-end > JS Tutorial > body text

What is the JavaScript history object?

青灯夜游
Release: 2018-12-13 18:04:09
Original
2888 people have browsed it

The history object of JavaScript is part of the window object and represents an array collection of URLs visited by the user; it is used to save the user's online history, starting from the moment the window is opened.

What is the JavaScript history object?

This article introduces the history object of JavaScript to everyone, so that everyone can have a simple understanding of the History object and know the properties and methods of the History object. I hope it will be helpful to you. .

Attributes of the History object

The History object has only one attribute, that is: length, used to return historical records The number of URLs in the table. Example:

history.length // 如果在当前窗口先后访问了三个网站,有了三个URL,就会返回3
Copy after login

Methods of the History object

The History object has three methods, which are:

forward(): Loads the previous URL in the history list.

back(): Load the next URL in the history list.

go(): Load a specific page in the history list, you can accept an integer as a parameter, for example:

history.go(1)
/*相当于*/
history.forward()

history.go(-1)
/*相当于*/
history.back()

history.history.go(0)  /*相当于刷新当前页面*/
Copy after login

Example of the History object method:

History object method can be used in the "return to previous page" link

1.html

<div id="demo">
	<a href="file:///D:/ksdler/Sublime%20Text/demo/2.html">2.html</a><br>
	<a href="#" id="backLink">返回上一页</a><br>

</div>
<script>  
document.getElementById(&#39;backLink&#39;).onclick = function () {
  window.history.back();
}
</script>
Copy after login

2.html

<div id="demo">
    <a href="file:///D:/ksdler/Sublime%20Text/demo/1.html">1.html</a><br>
    <a href="#" id="backLink">返回上一页</a><br>
</div>
<script>  
document.getElementById(&#39;backLink&#39;).onclick = function () {
  window.history.back();
}
</script>
Copy after login

Rendering :

What is the JavaScript history object?

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

The above is the detailed content of What is the JavaScript history object?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template