类:NavigationHistory
类:NavigationHistory
¥Class: NavigationHistory
管理导航条目列表,代表用户在应用内的浏览历史记录。
¥Manage a list of navigation entries, representing the user's browsing history within the application.
进程:主进程
该类不是从 'electron'
模块导出的。它仅可用作 Electron API 中其他方法的返回值。
¥Process: Main
This class is not exported from the 'electron'
module. It is only available as a return value of other methods in the Electron API.
每个 NavigationEntry 对应一个特定的访问页面。索引系统遵循顺序,其中最早访问的页面的条目位于索引 0,而最近访问的页面的条目位于索引 N。
¥Each NavigationEntry corresponds to a specific visited page. The indexing system follows a sequential order, where the entry for the earliest visited page is at index 0 and the entry for the most recent visited page is at index N.
此类中的某些 API 还接受偏移量,偏移量是一个整数,根据上述索引系统表示索引相对于当前条目的相对位置(即 1
的偏移量值表示在历史记录中前进一页)。
¥Some APIs in this class also accept an offset, which is an integer representing the relative
position of an index from the current entry according to the above indexing system (i.e. an offset
value of 1
would represent going forward in history by one page).
维护这个有序的导航条目列表可以在用户的浏览历史记录中实现前后无缝导航。
¥Maintaining this ordered list of navigation entries enables seamless navigation both backward and forward through the user's browsing history.
实例方法
¥Instance Methods
navigationHistory.canGoBack()
返回 boolean
- 浏览器是否可以返回上一个网页。
¥Returns boolean
- Whether the browser can go back to previous web page.
navigationHistory.canGoForward()
返回 boolean
- 浏览器是否可以前进到下一个网页。
¥Returns boolean
- Whether the browser can go forward to next web page.
navigationHistory.canGoToOffset(offset)
-
offset
整数¥
offset
Integer
返回 boolean
- 网页是否可以从当前条目转到指定的相对 offset
。
¥Returns boolean
- Whether the web page can go to the specified relative offset
from the current entry.
navigationHistory.clear()
清除导航历史记录。
¥Clears the navigation history.
navigationHistory.getActiveIndex()
返回 Integer
- 当前页面的索引,我们可以从中后退/前进或重新加载。
¥Returns Integer
- The index of the current page, from which we would go back/forward or reload.
navigationHistory.getEntryAtIndex(index)
-
index
整数¥
index
Integer
返回 NavigationEntry
- 给定索引处的导航条目。
¥Returns NavigationEntry
- Navigation entry at the given index.
如果索引越界(大于历史长度或小于 0),将返回 null。
¥If index is out of bounds (greater than history length or less than 0), null will be returned.
navigationHistory.goBack()
使浏览器返回网页。
¥Makes the browser go back a web page.
navigationHistory.goForward()
使浏览器前进一个网页。
¥Makes the browser go forward a web page.
navigationHistory.goToIndex(index)
-
index
整数¥
index
Integer
将浏览器导航到指定的绝对网页索引。
¥Navigates browser to the specified absolute web page index.
navigationHistory.goToOffset(offset)
-
offset
整数¥
offset
Integer
从当前条目导航到指定的相对偏移量。
¥Navigates to the specified relative offset from the current entry.
navigationHistory.length()
返回 Integer
- 历史长度。
¥Returns Integer
- History length.
navigationHistory.removeEntryAtIndex(index)
-
index
整数¥
index
Integer
删除给定索引处的导航条目。无法删除 "当前活动索引" 处的条目。
¥Removes the navigation entry at the given index. Can't remove entry at the "current active index".
返回 boolean
- 导航条目是否从 webContents 历史记录中删除。
¥Returns boolean
- Whether the navigation entry was removed from the webContents history.
navigationHistory.getAllEntries()
返回 NavigationEntry[]
- WebContents 完整历史记录。
¥Returns NavigationEntry[]
- WebContents complete history.
navigationHistory.restore(options)
恢复导航历史记录并在堆栈中加载给定的条目。将尽最大努力不仅恢复导航堆栈,还恢复各个页面的状态 - 例如包括 HTML 表单值或滚动位置。建议在创建任何导航条目之前调用此 API,因此最好在对 webContents
对象调用 loadURL()
或 loadFile()
之前。
¥Restores navigation history and loads the given entry in the in stack. Will make a best effort
to restore not just the navigation stack but also the state of the individual pages - for instance
including HTML form values or the scroll position. It's recommended to call this API before any
navigation entries are created, so ideally before you call loadURL()
or loadFile()
on the
webContents
object.
此 API 允许你创建旨在恢复、重新创建或克隆其他 webContents 的常见流程。
¥This API allows you to create common flows that aim to restore, recreate, or clone other webContents.
返回 Promise<void>
- 当页面完成加载所选导航条目时,promise 将解决(参见 did-finish-load
),如果页面加载失败,promise 将拒绝(参见 did-fail-load
)。已附加 noop 拒绝处理程序,这可以避免未处理的拒绝错误。
¥Returns Promise<void>
- the promise will resolve when the page has finished loading the selected navigation entry
(see did-finish-load
), and rejects
if the page fails to load (see
did-fail-load
). A noop rejection handler is already attached, which avoids unhandled rejection errors.