【问题标题】:HTML5 Notifications in a Chrome extension - Can the close button be disabled?Chrome 扩展中的 HTML5 通知 - 可以禁用关闭按钮吗?
【发布时间】:2012-04-10 20:22:37
【问题描述】:

我正在使用此处描述的通知http://code.google.com/chrome/extensions/notifications.html 进行 chrome 扩展。

有没有办法覆盖默认添加的 X 按钮(关闭按钮)的行为?或者我可以禁用它吗?

【问题讨论】:

    标签: javascript html google-chrome google-chrome-extension notifications


    【解决方案1】:

    无法修改通知弹出窗口的基本布局。
    没有办法阻止通知被关闭。虽然不推荐,但您可以绑定一个 onclose 事件,该事件会在通知被销毁时触发。

    我创建了一个演示,它显示了一个半持久通知http://jsfiddle.net/n385r/

    在 Chrome 扩展程序中,"notifications" 权限必须在清单文件中设置。然后,可以添加一个半持久的通知弹出窗口,如下所示:

    (function repeat() {
        // Assume that /icon.png exists in the root of your extension
        webkitNotifications.createNotification('/icon.png', 'Title', 'Message.');
        note.onclose = function() {
            // On close, repeat:
            repeat();
        };
        note.show();
    })(); // Start the notification
    

    我的互动演示(http://jsfiddle.net/n385r/)包含更多细节,可以移除通知。之前显示的代码一直显示通知,直到用户禁用扩展程序或关闭 Chrome。可以想象,这对用户不友好,您不应该使用半永久通知。

    文档

    【讨论】:

      猜你喜欢
      • 2015-11-09
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 1970-01-01
      • 2011-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多