-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Document Notification.navigate property #43283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pepelsbey
wants to merge
10
commits into
mdn:main
Choose a base branch
from
pepelsbey:notification-navigate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+123
−9
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
be907d9
Document Notification.navigate property
pepelsbey fd27095
Apply suggestions from code review
pepelsbey 7a53471
Update intro, reorder/simplify demos
pepelsbey 6a38004
Clarify the intro
pepelsbey f9c6e2a
Clarify the clicks description
pepelsbey 806ee55
Mention click and update notificationclick
pepelsbey 3f4a074
Mention navigation in the guide
pepelsbey 5532b4e
Fix redirect
pepelsbey 103ca01
Update the example to more realistic one
pepelsbey 2d9ce43
Fix concepts to explain (non-)persistent notifications
hamishwillee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| --- | ||
| title: "Notification: navigate property" | ||
| short-title: navigate | ||
| slug: Web/API/Notification/navigate | ||
| page-type: web-api-instance-property | ||
| status: | ||
| - experimental | ||
| browser-compat: api.Notification.navigate | ||
| --- | ||
|
|
||
| {{APIRef("Web Notifications")}}{{securecontext_header}}{{SeeCompatTable}} {{AvailableInWorkers}} | ||
|
|
||
| The **`navigate`** read-only property of the {{domxref("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 {{domxref("Notification.Notification", "Notification()")}} constructor or {{domxref("ServiceWorkerRegistration.showNotification()")}}. | ||
|
|
||
| Normally, activating a non-persistent notification fires the {{domxref("Notification.click_event", "click")}} event on its {{domxref("Notification")}} object, and activating a persistent notification fires the {{domxref("ServiceWorkerGlobalScope.notificationclick_event", "notificationclick")}} event on the {{domxref("ServiceWorkerGlobalScope")}}. | ||
pepelsbey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 {{glossary("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. | ||
|
|
||
| ```js | ||
| 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); // "" | ||
| ``` | ||
pepelsbey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### 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 {{domxref("ServiceWorkerGlobalScope.notificationclick_event", "notificationclick")}} event. | ||
|
|
||
| ```js | ||
| // Inside a service worker | ||
| self.registration.showNotification("Order shipped!", { | ||
| body: "Your order #1234 has been shipped.", | ||
| navigate: "/orders/1234", | ||
| }); | ||
| ``` | ||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - [Using the Notifications API](/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API) | ||
| - {{domxref("Notification.Notification", "Notification()")}} constructor | ||
| - {{domxref("ServiceWorkerRegistration.showNotification()")}} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.