ブラウザ通知を追加するのが初めてです。ブラウザ通知の使い方は?私はどこから始めるべきか分からなかった。誰でも私にこれを始める方法についての提案を提供することはできますか?あなたのサイトやアプリケーションがHTTPSを介して提供されなければならない仕事をする、ブラウザの通知のためにブラウザ通知の使い方
1
A
答えて
0
それ以外のブラウザでは、文句を言わない私は自分のアプリケーションのためにこれを使用することが
mesg = {
title: "notification title",
body: "notification body",
icon: "location to an .ico image",
timer: true //for auto closing
}
// Let's check if the browser supports notifications
if (!('Notification' in window)) {
console.log('Browser does not support this feature.');
}else if (Notification.permission === 'granted') {
Notification.requireInteraction = false;
if (mesg.title !== 'undefined') {
const notification = new Notification(mesg.title, {
body: mesg.body,
icon: mesg.icon
});
if (mesg.timer) {
setTimeout(function() {
notification.close();
}, 5000);
}
return notification;
}// close if undefined
} else if (Notification.permission !== 'denied') {
alert('Please click Allow for enabling browser notifications');
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === 'granted') {
if (mesg.title !== 'undefined') {
const notification = new Notification(mesg.title, {
body: mesg.body,
icon: mesg.icon
});
if (mesg.timer) {
setTimeout(function() {
notification.close();
}, 5000);
}
return notification;
}// close if undefined
} else {
alert('Permission Denied :[');
}
});
}
、あなたが重複したコードを削除し、それをリファクタリングすることができますことができます。参照
コード
document.addEventListener('DOMContentLoaded', function() {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
});
と
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
icon: 'Icon Link',
body: "Notification Body",
});
notification.onclick = function() {
window.open("Href Here");
};
}
0
0
例
function notifyMe() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check whether notification permissions have already 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.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.
}
notifyMe();
カ月の通知を表示するための許可を要求するための
関連する問題
- 1. ブラウザでのFirebaseの通知
- 2. ブラウザへのSNS通知
- 3. SignalRとPush通知の使い方は?
- 4. デフォルト通知スタイルの使い方は?
- 5. ブラウザのデスクトップ通知ハンドルonCloseイベント
- 6. ブラウザのプッシュ通知用のスタイルをカスタマイズする方法
- 7. FirefoxのWebブラウザにプッシュ通知を送信する方法は?
- 8. Laravel 5.2ブラウザでポップアップユーザー通知 - 例、ヒント?
- 9. ブラウザ間で通知を表示する方法
- 10. Javaを使用してFirefoxブラウザにプッシュ通知を送信する方法
- 11. レールでサポートされていないブラウザ通知
- 12. ブラウザが閉じているときの通知
- 13. サーバー上のイベントについてブラウザに通知する
- 14. ブラウザのサービスワーカーに新しいアプリケーションバージョンを通知します
- 15. UIApplication handleOpenURL通知の使用方法
- 16. イオンプッシュ通知が通知バーに通知を表示しない
- 17. 通知エリアと通知トレイのAndroidで異なる通知アイコンを使用する方法
- 18. 通知ウィンドウから通知をクリアする方法通知ウィンドウを開いたままにする方法
- 19. サウンドを使ってwhatsapp通知のようなヘッドアップ通知をする方法
- 20. どちらを使うのがいいですか?フラッシュ[:通知] vs:通知?
- 21. Toast通知の通知ハブキャッシュ
- 22. 使用laravel通知
- 23. 正方形、通知
- 24. アンドロイドアプリのステータスバー通知のようなCustomSliding Drawerの使い方
- 25. 新しいWifiネットワークの通知方法
- 26. 通知が通知されたときに通知を受け取る方法
- 27. 特定のユーザー(ウェブ)へのブラウザ通知の送信
- 28. Firebase通知を使用してiOSでカスタム通知を送信する方法。
- 29. HTML 5通知を使用して通知をスケジュールする方法 - Web API?
- 30. 私の通知は、事前通知マネージャを使用して