NavigationCurrentEntryChangeEvent

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

导航 APINavigationCurrentEntryChangeEvent 接口是 currententrychange 事件的事件对象,该事件在 Navigation.currentEntry 发生更改时触发。

此事件将在以下情况下触发:同一文档导航(例如 back()traverseTo())、替换(即 navigate() 调用,其中 history 设置为 replace),或其他更改条目状态的调用(例如 updateCurrentEntry(),或历史记录 APIHistory.replaceState())。

此事件在导航提交后触发,这意味着可见 URL 已更改,并且已发生 NavigationHistoryEntry 更新。它对于从使用较旧的 API 特性(如 hashchangepopstate 事件)迁移非常有用。

Event NavigationCurrentEntryChangeEvent

构造函数

创建一个新的 NavigationCurrentEntryChangeEvent 对象实例。

实例属性

从其父级 Event 继承属性。

from 只读 实验性

返回导航来源的 NavigationHistoryEntry

返回导致改变的导航的类型。

示例

导航数据上报:

js
navigation.addEventListener("currententrychange", () => {
  const data = navigation.currentEntry.getState();
  submitAnalyticsData(data.analytics);
});

设置每个条目事件:

js
navigation.addEventListener("currententrychange", () => {
  navigation.currentEntry.addEventListener("dispose", genericDisposeHandler);
});

规范

Specification
HTML
# the-navigationcurrententrychangeevent-interface

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
NavigationCurrentEntryChangeEvent
Experimental
NavigationCurrentEntryChangeEvent() constructor
Experimental
from
Experimental
navigationType
Experimental

Legend

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

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

参见