html5 - webkitNotifications - SECURITY_ERR: DOM Exception 18 - script, OK - button -
i followed http://www.beakkon.com/tutorial/html5/desktop-notification tutorial html 5 desktop notifications. demo on page work me. if copy entire code works so, but... when call method javascript don't display niether notification or permision request. instead raises security_err: dom exception 18
.
it seems error raised line creates notification itself.
has glue why button works , calling function directly not?
my current code:
function requestpermission(callback) { window.webkitnotifications.requestpermission(callback); } function notif() { if (window.webkitnotifications.checkpermission() > 0) { requestpermission(notif); } notification = window.webkitnotifications.createhtmlnotification('http://localhost:3000/images/rails.png'); notification.show(); }
does not compute:
notif();
computes:
<button onclick="notif()">notify</button>
google chrome: 9.0.597.84 (oficiální sestavení 72991)
webkit: 534.13
security_err: dom exception 18
valid if user hasn't allowed request have notifications.
the reason why happening because requestpermission
asynchronous. once user clicks on allow, permission granted, allow use html5 notifications feature.
in case, not waiting user click on allow button, automatically trying create html5 notification without evening waiting confirmation. if rearrange conditionals, should work.
function requestpermission(callback) { window.webkitnotifications.requestpermission(callback); } function notif() { if (window.webkitnotifications.checkpermission() > 0) { requestpermission(notif); } else { notification = window.webkitnotifications.createhtmlnotification('http://localhost:3000/images/rails.png'); notification.show(); } }
as notice above, place notification creation in conditional statement, when callback gets fired guaranteed have permission.
Comments
Post a Comment