类:NavigationHistory
类:NavigationHistory
🌐 Class: NavigationHistory
管理导航条目列表,表示用户在应用中的浏览历史。
进程: 主进程
此类未从 'electron' 模块导出。它仅作为 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 也接受一个 offset 参数,它是一个整数,表示根据上述索引系统,从当前条目起的索引相对位置(即 offset 值为 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整数
返回 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整数
返回 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整数
将浏览器导航到指定的绝对网页索引。
🌐 Navigates browser to the specified absolute web page index.
navigationHistory.goToOffset(offset)
offset整数
从当前条目导航到指定的相对偏移量。
🌐 Navigates to the specified relative offset from the current entry.
navigationHistory.length()
返回 Integer - 历史长度。
🌐 Returns Integer - History length.
navigationHistory.removeEntryAtIndex(index)
index整数
删除指定索引处的导航条目。无法删除“当前活动索引”的条目。
🌐 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),如果页面加载失败则会被拒绝(参见 did-fail-load)。已经附加了一个空操作的拒绝处理程序,这可以避免未处理的拒绝错误。
🌐 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.