title | slug |
---|---|
history |
Mozilla/Add-ons/WebExtensions/API/history |
{{AddonSidebar}}
使用 history
API 与浏览器历史记录进行交互。
Note
下载也被当做一个 HistoryItem
对象。因此,history.onVisited
等事件也会被下载所触发。
浏览器历史记录是对用户所访问的页面按时间顺序进行的记录和保存。history API 可以帮你实现以下功能:
然而,用户可能多次访问单个页面,因此 API 中有访问集合“visits”的概念。所以,该 API 还可以做如下使用:
使用该 API 之前,扩展程序必须在其 manifest.json
文件中获取 history 的许可。
- {{WebExtAPIRef("history.TransitionType")}}
- : 描述浏览器如何转到特定页面。
- {{WebExtAPIRef("history.HistoryItem")}}
- : 提供浏览器历史记录中单个特定页面的详细信息。
- {{WebExtAPIRef("history.VisitItem")}}
- : 描述对一个页面的单次访问。
- {{WebExtAPIRef("history.search()")}}
- : 在浏览器历史记录中查找符合给定条件的
history.HistoryItem
- : 在浏览器历史记录中查找符合给定条件的
- {{WebExtAPIRef("history.getVisits()")}}
- : 获取指定页面的访问集信息。
- {{WebExtAPIRef("history.addUrl()")}}
- : 为浏览器历史记录添加一个指定页面的访问。
- {{WebExtAPIRef("history.deleteUrl()")}}
- : 移除浏览器历史记录中所有对指定 URL 的访问。
- {{WebExtAPIRef("history.deleteRange()")}}
- : 移除指定时间段内对用户指定页面的访问。
- {{WebExtAPIRef("history.deleteAll()")}}
- : 移除浏览器历史记录中的所有访问。
- {{WebExtAPIRef("history.onTitleChanged")}}
- : 当用户访问的页面标题被记录时触发。
- {{WebExtAPIRef("history.onVisited")}}
- : 每次用户访问页面时会触发,并提供该页面的 {{WebExtAPIRef("history.HistoryItem")}} 数据。
- {{WebExtAPIRef("history.onVisitRemoved")}}
- : 当一个 URL 被彻底从浏览器历史记录中移除时触发。
{{Compat}}
{{WebExtExamples("h2")}}
Note
该 API 基于 Chromium 的chrome.history
API。该文档由 Chromium 代码中的history.json
衍生而来。
微软 Edge 兼容性数据由微软公司提供并包含在如下证书中——Creative Commons Attribution 3.0 United States License.