Web History API
- Previous Page Web Form API
- Next Page Web Storage API
Web History API 提供了访问 windows.history 对象的简单方法。
window.history 对象包含用家访问过的 URL(网站)。
所有浏览器都支援 Web History API:
Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|
支援 | 支援 | 支援 | 支援 | 支援 |
History back() Method
back() 方法和载入 windows.history 列表中的前一个 URL。
This is the same as clicking the 'back arrow' in the browser.
Example
<button onclick="myFunction()">Back</button> <script> function myFunction() { window.history.back(); } </script>
History go() Method
The go() method loads a specific URL from the history list:
Example
<button onclick="myFunction()">Go back two pages</button> <script> function myFunction() { window.history.go(-2); } </script>
History Object Attribute
Attribute | Description |
---|---|
length | Return the number of URLs in the history list. |
History Object Method
Method | Description |
---|---|
back() | Load the previous URL from the history list. |
forward() | Load the next URL from the history list. |
go() | Load a specific URL from the history list. |
- Previous Page Web Form API
- Next Page Web Storage API