https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification
ここにWEBでNOTIFYメッセージする方法が書いてあります。
この関数,動作するのはわかったのですが、
その下の記述にある
To invoke the above function at an appropriate time, you could use the ServiceWorkerGlobalScope.onnotificationclick event handler.
の意味がさっぱり分かりません。
どうすればclickイベントがとれるのでしょうか?
ちなみに
Javascript
1navigator.serviceWorker.register('/sb_app/js/sw.js'); 2Notification.requestPermission(function(result) { 3 if (result === 'granted') { 4 navigator.serviceWorker.ready.then(function(registration) { 5 var options = { 6 body: "How are you?", 7 icon:"https://www.google.com/s2/favicons?domain=www.yahoo.com", 8 onClick: function onNotificationClicked() { 9 console.log('Notification clicked.'); 10 } 11 }; 12 13 registration.showNotification('Notification with ServiceWorker',options); 14 15 var options2 = { tag : 'user_alerts' }; 16 registration.getNotifications(options2).then(function(notifications) { 17 console.log("demo"); 18 }) ; 19 20 }); 21 } 22}); 23 24self.onnotificationclick = function(event) { 25 console.log('On notification click: ', event.notification.tag); 26 27};
とかやったのですがハズレでした。
お教えいただけるとありがたいです
あなたの回答
tips
プレビュー