如何设置HTML5桌面通知的样式?

时间:2015-06-09 07:02:16

标签: javascript jquery html5 notifications

我尝试为我的网站发送桌面通知, 我发现this指南很有用。 并成功完成了它。

我也在这里发布代码:

HTML:

<button id='button'>Notify me!</button>

JS:

$('input[type=button]').click(notifyMe);

function notifyMe() {
  if (!("Notification" in window)) {
    alert("This browser does not support desktop notification");
  } else if (Notification.permission === "granted") {
    var options = {
      body: "This is the body of the notification",
      icon: "icon.jpg",
      dir: "ltr"
    };
    var notification = new Notification("Hi there", options);
  } else if (Notification.permission !== 'denied') {
    Notification.requestPermission(function(permission) {
      if (!('permission' in Notification)) {
        Notification.permission = permission;
      }

      if (permission === "granted") {
        var options = {
          body: "This is the body of the notification",
          icon: "icon.jpg",
          dir: "ltr"
        };
        var notification = new Notification("Hi there", options);
      }
    });
  }
}

Demo

我的问题是,有办法改变它的默认样式吗?

1 个答案:

答案 0 :(得分:3)

我担心编辑的内容比你正在做的更多。就像警报元素一样,浏览器会格式化通知。