这篇翻译不完整。请帮忙从英语翻译这篇文章

使用 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被彻底从浏览器历史记录中移除时触发。

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
HistoryItemChrome Full support YesEdge No support NoFirefox Full support 49Opera Full support YesFirefox Android No support No
TransitionTypeChrome Full support YesEdge No support NoFirefox Full support 50Opera Full support YesFirefox Android No support No
VisitItemChrome Full support YesEdge No support NoFirefox Full support 50Opera Full support YesFirefox Android No support No
addUrlChrome Full support YesEdge No support NoFirefox Full support 49Opera Full support YesFirefox Android No support No
deleteAllChrome Full support YesEdge No support NoFirefox Full support 49Opera Full support YesFirefox Android No support No
deleteRangeChrome Full support YesEdge No support NoFirefox Full support 49Opera Full support YesFirefox Android No support No
deleteUrlChrome Full support YesEdge No support NoFirefox Full support 49Opera Full support YesFirefox Android No support No
getVisitsChrome Full support YesEdge No support NoFirefox Full support 50Opera Full support YesFirefox Android No support No
onTitleChangedChrome No support NoEdge No support NoFirefox Full support 55Opera No support NoFirefox Android No support No
onVisitRemovedChrome Full support YesEdge No support NoFirefox Full support 50Opera Full support YesFirefox Android No support No
onVisitedChrome Full support YesEdge No support NoFirefox Full support 50
Notes
Full support 50
Notes
Notes Before version 56, the result object's 'title' was always an empty string. From version 56 onwards, it is set to the last known title, if that is available, or an empty string otherwise.
Opera Full support YesFirefox Android No support No
searchChrome Full support YesEdge No support NoFirefox Full support 49Opera Full support YesFirefox Android No support No

Legend

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

Example extensions

致谢

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

微软 Edge 兼容性数据由微软公司提供并包含在如下证书中—— Creative Commons Attribution 3.0 United States License.

文档标签和贡献者

此页面的贡献者: Jessy.D., wbamberg
最后编辑者: Jessy.D.,