JavaScript - Notification API in webbrowser -
i made notifications web service. code looks (two first lines mental shortcut):
check_how_many_alerts(); loop count(check_how_many_alerts){ var n = new notification("alert!",{ icon: "alert.png", body: variable }); alert_name = variable; n.onshow = function () { settimeout(n.close.bind(n), 10000);} n.onclick = function() { $.ajax({ url: 'notif_accept.php', type: 'get', data: 'id=' + alert_name, success: function(output) { alert('success, server says '+output); }, error: function() { alert('something went wrong'); } }); } }
the problem when have 2 or more alerts, of them have same url in .onclick function. should have urls different "alert_names"?
if want dynamically specify you're url: 'notif_accept.php'
ajax call, add together method notification
's prototype:
notification.prototype.bind_click = function (url) { this.onclick = function() { $.ajax({ url: url, type: 'get', data: 'id=' + alert_name, success: function(output) { alert('success, server says '+output); }, error: function() { alert('something went wrong'); } }); } } n = new notification("alert!",{ icon: "alert.png", body: variable }); n.bind_click('notif_accept.php');
javascript api google-chrome firefox notifications
No comments:
Post a Comment