我在自定义设计的网站上使用notify.js小部件。当来自php文件的加载数据的值为“1”时,应该向用户显示通知。我使用setInterval方法,因为我想每5秒重新加载一次该函数。 例如:
setInterval(function(){
$('.orders-undelivered').load("undelivered-orders.php");
var orders = $('.orders-undelivered').text();
if (orders == "1"){
function onShowNotification () {
console.log('notification is shown!');
}
function onCloseNotification () {
console.log('notification is closed!');
}
function onClickNotification () {
console.log('notification was clicked!');
window.location.href='http://mywebsite.com/admin'
}
function onErrorNotification () {
console.error('Error showing notification. You may need to request permission.');
}
function doNotification () {
var myNotification = new Notify('New Order', {
body: 'Click here',
tag: 'My unique id',
icon:'http://mywebsite.com/images/logo.gif',
notifyShow: onShowNotification,
notifyClose: onCloseNotification,
notifyClick: onClickNotification,
notifyError: onErrorNotification,
timeout: 4
});
myNotification.show();
}
}
),5000}
它完美无缺,直到我在我的电脑中打开其他窗口或标签和几个程序。之后,通知无法打开。为了查看通知,我必须单击运行notify.js的选项卡。
由于
答案 0 :(得分:0)
我认为你需要将notifyJs声明到网站的索引中,或者将其放入每个视图中。