此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

WindowClient:navigate() 方法

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2022年9月⁩.

备注: 此特性仅在 Service Worker 中可用。

WindowClient 接口的 navigate() 方法会将指定的 URL 加载到受控的客户端页面中,然后返回一个 Promise,其兑现为现有的 WindowClient

语法

js
navigate(url)

参数

url

要导航到的位置。

返回值

如果该 URL 与 service worker 同源,则返回一个兑现为现有 WindowClientPromise;否则返回 null

规范

Specification
Service Workers
# client-navigate

浏览器兼容性