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

Notification: navigate property

· 52CE 我爱测

The **`navigate`** read-only property of the Notification interface contains the URL the user agent will navigate to when the user activates the notification.

Web Notifications

The navigate read-only property of the Notification interface contains the URL the user agent will navigate to when the user activates the notification.

This is the resolved value of the URL, if any, that was specified in the navigate option of the Notification.Notification constructor or ServiceWorkerRegistration.showNotification().

Normally, activating a non-persistent notification fires the Notification.click_event event on its Notification object, and activating a persistent notification fires the ServiceWorkerGlobalScope.notificationclick_event event on the ServiceWorkerGlobalScope.

When a notification with a navigation URL is activated by the user, the user agent navigates to the specified URL instead of firing either of these events. This allows notifications to direct users to a specific page without requiring an event handler.

Value

A string containing a URL, or an empty string if no navigation URL has been set.

Examples

Reading the navigate property value

The navigate property returns the resolved URL string when a navigation URL has been set, or an empty string otherwise.

const notification = new Notification("New message from Alice", {
  body: "Hey, are you free for lunch?",
  navigate: "/messages/alice",
});

// The property contains the resolved absolute URL
console.log(notification.navigate); // e.g. "https://example.com/messages/alice"

// Without a navigate option, the property is an empty string
const basic = new Notification("Hello!");
console.log(basic.navigate); // ""

Using navigate with a service worker

When using persistent notifications through a service worker, the navigate option allows the notification to open a page when activated, without needing to handle the ServiceWorkerGlobalScope.notificationclick_event event.

// Inside a service worker
self.registration.showNotification("Order shipped!", {
  body: "Your order #1234 has been shipped.",
  navigate: "/orders/1234",
});

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

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

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