简体   繁体   English

Chrome扩展程序通知未显示contextMessage吗?

[英]Chrome Extension notifications not showing contextMessage?

In my code, the contextMessage is not showing up I know it works fine with chrome.notifications.create , but if I use that then I can't make it so the notification never disappears without being closed or clicked on 在我的代码中,contextMessage没有显示出来,我知道它可以与chrome.notifications.create一起chrome.notifications.create ,但是如果我使用它,那么我将无法做到这一点,因此通知不会在没有关闭或单击的情况下消失

function Notify(Title, Body, miniMsg, Url, Icon) {
    var notification = new Notification(Title, {
        icon: Icon||"Logo.png",
        body: Body,
        contextMessage:miniMsg
    });
    notification.onclick = function () {
        window.open(Url);
    }
}

Thanks! 谢谢!

The answer is simple: Compatibility. 答案很简单:兼容性。

You are trying to use a feature that isn't supported in Chrome without the webkit prefix, according to MDN . 根据MDN的说法,您正在尝试使用Chrome中不带webkit前缀不支持的功能。 For a Google Chrome extension, it is suggested to use the chrome.notifications API . 对于Google Chrome扩展程序,建议使用chrome.notifications API

Using the chrome.notifications API, you are unable to specify how long the notifications stay open. 使用chrome.notifications API,您无法指定通知保持打开状态的时间。 However, another option is to use the chrome.experimental.notifications API, which would prevent you from publishing your extension to the webstore, and has very little documentation. 但是,另一种选择是使用chrome.experimental.notifications API,该API会阻止您将扩展程序发布到网上商店,并且文档很少。

You could also change the priority option in chrome.notifications.create to any integer between -2 to 2, where 2 is the highest, and would grant your notification the most display time. 您还可以将chrome.notifications.createpriority选项更改为-2到2之间的任何整数,其中2是最高的整数,并将为您的通知分配最多的显示时间。

Since you seem to be using the Notifications object, you might notice that your syntax does not match that shown in the MDN documentation. 由于您似乎正在使用Notifications对象,因此可能会注意到语法与MDN文档中显示的语法不匹配。 Primarily, there does not seem to be any contextMessage parameter for Notifications. 首先,似乎没有用于Notifications的contextMessage参数。 As a side note, the onclick callback won't work, since the Url parameter is no longer executed in the current scope. 附带说明一下, onclick回调将不起作用,因为Url参数不再在当前作用域中执行。 The anonymous function will not be able to see the Url parameter passed into Notify . 匿名函数将无法看到传递给NotifyUrl参数。 You also might want to check out compatibility and notes for Notifications . 您可能还需要查看兼容性和Notifications注释

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM