history

使用 history API 与浏览器历史记录进行交互。

备注: 下载也被当做一个 HistoryItem 对象。因此,history.onVisited等事件也会被下载所触发。

浏览器历史记录是对用户所访问的页面按时间顺序进行的记录和保存。history API 可以帮你实现以下功能:

然而,用户可能多次访问单个页面,因此 API 中有访问集合“visits”的概念。所以,该 API 还可以做如下使用:

使用该 API 之前,扩展程序必须在其 manifest.json 文件中获取 history 的许可

类型

history.TransitionType

描述浏览器如何转到特定页面。

history.HistoryItem

提供浏览器历史记录中单个特定页面的详细信息。

history.VisitItem

描述对一个页面的单次访问。

方法

history.search()

在浏览器历史记录中查找符合给定条件的history.HistoryItem

history.getVisits()

获取指定页面的访问集信息。

history.addUrl()

为浏览器历史记录添加一个指定页面的访问。

history.deleteUrl()

移除浏览器历史记录中所有对指定 URL 的访问。

history.deleteRange()

移除指定时间段内对用户指定页面的访问。

history.deleteAll()

移除浏览器历史记录中的所有访问。

事件

history.onTitleChanged

当用户访问的页面标题被记录时触发。

history.onVisited

每次用户访问页面时会触发,并提供该页面的 history.HistoryItem 数据。

history.onVisitRemoved

当一个 URL 被彻底从浏览器历史记录中移除时触发。

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
history
HistoryItem
HistoryItem.typedCount
TransitionType
VisitItem
addUrl
addUrl.title
addUrl.transition
addUrl.visitTime
deleteAll
deleteRange
deleteUrl
getVisits
onTitleChanged
onTitleChanged.id
onVisitRemoved
onVisited
search

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

示例扩展

备注: 该 API 基于 Chromium 的 chrome.history API。该文档由 Chromium 代码中的 history.json 衍生而来。