NavigationHistoryEntry:getState() 方法

Limited availability

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

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

NavigationHistoryEntry 接口的 getState() 方法返回由开发人员提供且与当前历史记录条目相关联的状态的克隆。

语法

js
getState()

参数

无。

返回值

表示状态的值。这可以是任何可结构化克隆的数据类型。

如果未定义状态或当前文档未完全激活,则返回 undefined

异常

无。

示例

js
async function handleReload() {
  // 通过 reload() 更新现有状态
  await navigation.reload({
    state: { ...navigation.currentEntry.getState(), newState: 3 },
  });

  // 将当前状态打印到控制台
  const current = navigation.currentEntry;
  console.log(current.getState());
}

规范

Specification
HTML
# dom-navigationhistoryentry-getstate-dev

浏览器兼容性

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
getState
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.

参见