大网数据广告活动
Web 标准与前端开发

Permissions-Policy: unload directive

· 52CE 我爱测

The HTTP Permissions-Policy header `unload` directive controls whether the current document is allowed to run `unload` event handlers.

The HTTP Permissions-Policy header unload directive controls whether the current document is allowed to run unload event handlers.

Where a defined policy disallows use of this feature, unload event handlers registered in the document will not run.

unload handlers are unreliable and prevent pages from being stored in the back/forward cache (bfcache). Blocking them lets a page stay eligible for the bfcache, even if third-party scripts in the page add unload handlers. See the usage notes for the unload event for alternatives.

Syntax

Permissions-Policy: unload=<allowlist>;
  • <allowlist>

Default policy

In Chrome, the default allowlist for unload is (), which means that unload handlers do not run unless a document opts in. Chrome originally used a default allowlist of *, and changed it gradually.

Examples

Blocking unload handlers

A site wants to make sure that no unload handlers run in its pages or in any of their embedded iframes, so that the pages remain eligible for the bfcache. It can do so by delivering the following HTTP response header:

Permissions-Policy: unload=()

Allowing unload handlers

A site that still depends on unload handlers can allow them to run in its top-level pages by delivering the following HTTP response header:

Permissions-Policy: unload=self

To also allow unload handlers in a cross-origin iframe whose origin is https://example.com, the embedding page must include that origin in its allowlist:

Permissions-Policy: unload=(self "https://example.com")

It must also include an iframe attribute on the <iframe> element:

<iframe src="https://example.com/embed" allow="unload"></iframe>

The document loaded in the iframe must also allow unload handlers, using its own Permissions-Policy: unload=self response header.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。