上記サイトを参考に、下記のようにhtmlファイルを作成しました。
firefoxへD&Dすると下記添付のように無事プッシュ通知が出ますが、
本番環境であるchromeでは下記添付のように通知許可の確認をした後にプッシュ通知が出ません。
htmlファイルは下記の通りです。
javascript
1 2<!DOCTYPE html> 3<html lang="en"> 4<head> 5<meta http-equiv="Content-Type" content="text/html" charset="utf-8"> 6 <script> 7 // ブラウザが通知をサポートしているか確認する 8 if (!('Notification' in window)) {//対応してない場合 9 alert('未対応のブラウザです'); 10 } 11 else { 12 // 許可を求める 13 Notification.requestPermission() 14 .then((permission) => { 15 16 if (permission === 'granted') {// 許可 17 18 var title = '薬剤に危険性あり'; 19 var options ={ 20 body: '詳細についてはこちらを参照ください URL', 21 icon: 'images/alert.png', 22 image: 'images/sample_48.png', 23 tag: '' 24 } 25 var n = new Notification(title,options); 26 console.log(n); 27 setTimeout(n.close.bind(n), 5000); 28 } 29 30 else if (permission == 'denied') {// 拒否 31 } 32 else if (permission == 'default') {// 無視 33 } 34 }); 35 } 36 37 </script> 38</html> 39
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/31 07:11
2018/01/31 07:14