Mid*_*sai 7 javascript push-notification web-notifications angularjs angularjs-directive
我正在尝试将网络通知放到我的网站上,这样当我在我的网站中添加任何新项目时,我的所有客户都会在浏览器中看到我的通知.
我选择了angular-web-notification,我在我的应用程序中通过Bower安装并在本地测试,它工作正常但是当我将我的网站部署到生产中时,我再次在生产中测试,通知仅在我的浏览器中出现允许我网站通知的所有客户.
这是我的代码:
.directive('showButton', ['webNotification', function (webNotification) {
return {
restrict: 'C',
scope: {
notificationTitle: '=',
notificationMsg: '=',
notificationUrl: '='
},
link: function (scope, element) {
console.log("coming to directive notifications")
element.on('click', function onClick() {
console.log("coming to directive notifications click")
if ((scope.notificationTitle) && (scope.notificationMsg)) {
webNotification.showNotification(scope.notificationTitle, {
body: scope.notificationMsg,
icon: 'https://lh3.googleusercontent.com/BCOE0vqCfr8aqpIKEF7QEt-qa7p8I7KDg58Juz6M6_YGb4l7phrO2vMvi_SDy10ucQ=w300',
onClick: function onNotificationClicked() {
console.log('Notification clicked.');
window.open(scope.notificationUrl, '_blank')
},
autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
}, function onShow(error, hide) {
if (error) {
window.alert('Unable to show notification: ' + error.message);
} else {
console.log('Notification Shown.');
setTimeout(function hideNotification() {
console.log('Hiding notification....');
hide(); //manually close the notification (you can skip this if you use the autoClose option)
}, 5000);
}
});
}
});
}
};
}]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
330 次 |
| 最近记录: |