From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../ja/web/api/notification/permission/index.html | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 files/ja/web/api/notification/permission/index.html (limited to 'files/ja/web/api/notification/permission') diff --git a/files/ja/web/api/notification/permission/index.html b/files/ja/web/api/notification/permission/index.html new file mode 100644 index 0000000000..b838e6089f --- /dev/null +++ b/files/ja/web/api/notification/permission/index.html @@ -0,0 +1,94 @@ +--- +title: Notification.permission +slug: Web/API/Notification/permission +tags: + - API + - DOM + - Notification + - Notifications + - Notifications API + - Property + - Reference + - プロパティ + - 通知 +translation_of: Web/API/Notification/permission +--- +

{{APIRef("Web Notifications")}}{{AvailableInWorkers}}{{securecontext_header}}

+ +

permission は {{domxref("Notification")}} インターフェイスの読み取り専用プロパティで、ユーザーが現在のオリジンに対してウェブ通知を表示することを許可したかどうか、現在の許可状態を表します。

+ +

構文

+ +
var permission = Notification.permission;
+ +

+ +

現在の許可を表す {{domxref("DOMString")}} です。以下の値が可能です。

+ + + +

+ +

以下のスニペットは、まず通知に対応しているかどうかをチェックし、現在のオリジンで通知を送信するための許可が付与されているかどうかをチェックし、必要であれば許可を要求してから通知を送信したい場合に使用することができます。

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

仕様書

+ + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName("Web Notifications","#dom-notification-permission","permission")}}{{Spec2('Web Notifications')}}Living standard
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.Notification.permission")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf