NavigateEvent:formData 属性
Baseline
2026
Newly available
Since January 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
NavigateEvent 接口的 formData 只读属性在导航为 POST 表单提交导航的情况下返回表示提交的数据的 FormData 对象,否则返回 null。
值
FormData 对象,或 null。
示例
js
navigation.addEventListener("navigate", (event) => {
// 有些导航,例如跨源导航,我们无法拦截。让浏览器正常处理这些导航。
if (!event.canIntercept) {
return;
}
// 不要拦截片段导航或下载。
if (event.hashChange || event.downloadRequest !== null) {
return;
}
event.intercept({
handler() {
if (event.formData) {
processFormDataAndUpdateUI(event.formData, event.signal);
} else {
doSinglePageAppNav(event.destination, event.signal);
}
},
});
});
规范
| Specification |
|---|
| HTML> # dom-navigateevent-formdata-dev> |
浏览器兼容性
参见
- 现代客户端路由:导航 API
- 导航 API 说明
- Domenic Denicola 的导航 API 在线演示