Notification 的只读属性 permission 用来表明用户是否允许当前域显示Web Notification. 


此特性在 Web Worker 中可用。


var permission = Notification.permission;


permission 的类型为 DOMString . 该属性的可能值为:

  • granted: 用户已经明确的授予了显示通知的权限。.
  • denied: 用户已经明确的拒绝了显示通知的权限。
  • default: 用户还未被询问是否授权; 这种情况下权限将视为 denied.



function notifyMe() {
  // Let's check if the browser supports notifications
  if (!("Notification" in window)) {
    console.log("This browser does not support desktop notification");

  // Let's check whether notification permissions have alredy been granted
  else if (Notification.permission === "granted") {
    // If it's okay let's create a notification
    var notification = new Notification("Hi there!");

  // Otherwise, we need to ask the user for permission
  else if (Notification.permission !== 'denied' || Notification.permission === "default") {
    Notification.requestPermission(function (permission) {
      // If the user accepts, let's create a notification
      if (permission === "granted") {
        var notification = new Notification("Hi there!");

  // At last, if the user has denied notifications, and you
  // want to be respectful there is no need to bother them any more.


Specification Status Comment
Notifications API
Living Standard Living standard

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 5 webkit (see notes)
(Yes) 4.0 moz (see notes)
未实现 25 6 (see notes)
Available in workers ? ? 41.0 (41.0) ? ? ?
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ?


(Yes) 4.0 moz (see notes)
1.0.1 moz (see notes)
未实现 ? 未实现


Available in workers ? ? ? 41.0 (41.0) ? ? ? ? ?

Firefox OS notes

{{Page("/en-US/docs/Web/API/Notifications_API", "Firefox OS notes")}}

Chrome notes

{{Page("/en-US/docs/Web/API/Notifications_API", "Chrome notes")}}

Safari notes

{{Page("/en-US/docs/Web/API/Notifications_API", "Safari notes")}}

See also