Skip to content Skip to sidebar Skip to footer

WebkitNotifications - SECURITY_ERR: DOM Exception 18 - Script, OK - Button

I followed http://www.beakkon.com/tutorial/html5/desktop-notification tutorial for html 5 desktop notifications. The demo on that page work for me. If i copy entire code it works s

Solution 1:

SECURITY_ERR: DOM Exception 18 is valid if the user hasn't allowed your request to have notifications.

The reason why this is happening is simply because requestPermission is asynchronous. Once the user clicks on Allow, for permission to be granted, it will then allow you to use HTML5 notifications feature.

In your case, your not waiting for the user to click on Allow button, it is automatically trying to create the HTML5 notification without evening waiting for their confirmation. If you rearrange your conditionals, it 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 you notice above, place the notification creation in the conditional statement, when a callback gets fired it will be guaranteed to have permission.


Solution 2:

I believe the createHtmlNotification accepts only one parameter, and that is to be a url to an HTML document.


Post a Comment for "WebkitNotifications - SECURITY_ERR: DOM Exception 18 - Script, OK - Button"