【发布时间】:2017-02-21 19:09:27
【问题描述】:
我想从数据库向用户列表发送通知。
我找到了发送推送通知的解决方案:
// request permission on page load
document.addEventListener('DOMContentLoaded', function () {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe() {
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
body: "Hey there! You've been notified!",
});
notification.onclick = function () {
window.open("https://stackoverflow.com/a/13328397/1269037");
};
}
}
(来源:Chrome desktop notification example)如何配置它以向特定用户发送特定通知? 让我们假设我想向表 user_notification 的所有用户发送通知。 我尝试使用
<?php
$sqx = "SELECT * FROM `user_js` ";
?>
在代码中,但也无济于事
【问题讨论】:
-
@JayBlanchard 我不同意。我认为这是一个“特定的编码问题”。我只是不知道如何配置它
-
当我将此标记为“太宽泛”时,问题中没有代码。
-
@JayBlanchard.. 感谢您的耐心等待。现在,你能帮我找到解决办法吗?
-
目前还没有办法直接将Web通知从服务器推送到客户端。只能使用 websockets 或者长轮询 ajax 连接服务器,然后再新建一个通知对象。
-
目前草稿中有一个 Notifications Service Worker RFC,可以直接向客户端推送通知,即使网站暂时未打开。
标签: javascript php google-chrome push-notification notifications