Перевод не завершен. Пожалуйста, помогите перевести эту статью с английского.

permission  - это свойство только для чтения у Notification интерфейса указывающее на согласие пользователя с показом уведомлений из данного источника (страницы, на которой в данный момент находится пользователь).

Примечание: Эта возможность доступна в Web Workers.

Syntax

var permission = Notification.permission;

Value

A DOMString representing the current permission. The value can be:

  • granted: The user has explicitly granted permission for the current origin to display system notifications.
  • denied: The user has explicitly denied permission for the current origin to display system notifications.
  • default: The user decision is unknown; in this case the application will act as if permission was denied.

Examples

The following fairly verbose snippet could be used if you wanted to first check whether notifications are supported, then check if permission has been granted for the current origin to send notifications, then request permission if required, before then sending a notification.

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.
}

Specifications

Specification Status Comment
Notifications API
Определение 'permission' в этой спецификации.
Живой стандарт Living standard

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 5 webkit (see notes)
22
(Да) 4.0 moz (see notes)
22
Нет 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 ?

(Да)

(Да) 4.0 moz (see notes)
22
1.0.1 moz (see notes)
1.2
Нет ? Нет

(Да)

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

Firefox OS notes

Chrome notes

Safari notes

See also

Метки документа и участники

 Внесли вклад в эту страницу: vladislav251990
 Обновлялась последний раз: vladislav251990,