Chrome通知的操作无效 [英] actions for chrome notification not working

查看:535
本文介绍了Chrome通知的操作无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试创建Chrome通知,我想在通知中添加操作,以便用户可以选择选项。我试图运行此代码但由于某些原因它不起作用:

Hello I am trying to create a chrome notification and I want to add actions onto the notification so the user can select the options. I have tried to run this code but it doesnt work for some reason:

var options = {
    type: "basic",
    title: "Restock",
    message: "Tee Black",
    iconUrl: '/images/Hp_Beta7.png',
    actions: [
        {title: "small", action: "action1"},
        {title: "medium", action: "action2"}
        ]
};

chrome.notifications.create(options, callback);

function callback() {
    console.log("popup done");
}

通知工作没有动作部分,但我希望能够拥有在通知中选择,每次我尝试运行此脚本时都会收到此错误:

the notification works fine without the actions part but I want to be able to have a select in the notification and every time I try and run this script I get this error:

Uncaught SyntaxError: Unexpected identifier

指向操作:[行

有什么东西我错过了吗?

is there something That I am missing?

任何帮助都是apreciated。谢谢你< 3!

Any help is apreciated. Thank You <3 !

推荐答案

属性 actions 不存在通知。 按钮用于在通知中添加操作按钮。

The property "actions" does not exist for notifications. "buttons" is used to add action buttons in the notification.

此外,在 chrome.notifications.create(options,callback); ,参数列表不正确,因为第一个参数是 notificationId 这是如果没有使用,设置为

Also, in "chrome.notifications.create(options, callback);", the parameter list is not correct since the first parameter is "notificationId" which is set to "" in case not used.

这是一个答案,它解释了如何使用按钮chrome通知 - 有没有办法在谷歌浏览器的通知中插入动作按钮

Here is an answer which explains well how to use the buttons in chrome notification- Is there any way to insert action buttons in notification in Google Chrome

background.js

    var myNotificationID = null;
    var options = {
        type: "basic",
        title: "Restock",
        message: "Tee Black",
        iconUrl: "/images/Hp_Beta7.png",
        buttons: [
            {title: "small", iconUrl: "/images/..."},
            {title: "medium", iconUrl: "/images/..."}
        ]
    }
    chrome.notifications.create("", options, function(notificationId){
        myNotificationID = notificationId;
    });

    chrome.notifications.onButtonClicked.addListener(function(notifId, btnIdx) {
        if (notifId === myNotificationID) {
            if (btnIdx === 0) {
                action1();
            } else if (btnIdx === 1) {
                action2();
            }
        }
    });

这篇关于Chrome通知的操作无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆