【问题标题】:chrome extension disable notification sound on click of close notification buttonchrome 扩展在单击关闭通知按钮时禁用通知声音
【发布时间】:2015-11-09 22:45:42
【问题描述】:

我已经创建了提醒应用程序,它允许用户创建、编辑和删除提醒,我还创建了声音通知,但是当我单击通知弹出 html 的关闭按钮时,我在这里遇到了一个问题,它应该使声音关闭继续。我该如何解决这个问题?

以下是我的 background.js 代码

  function audioNotification(){
   var yourSound = new Audio('http://www.html5rocks.com/en/tutorials/audio/quick/test.ogg');
    yourSound.play();
  }

【问题讨论】:

    标签: javascript google-chrome google-chrome-extension google-chrome-devtools google-chrome-app


    【解决方案1】:

    您应该在函数之外创建一个变量,以便您仍然可以引用该变量。

    试试这个

    var yourSound; // <- moved outside of function
    
    function audioNotification(){
      // ...
      yourSound = new Audio('http://www.html5rocks.com/en/tutorials/audio/quick/test.ogg');
      yourSound.play();
    

    }

    然后停止它调用你的 onclick() 部分

    yourSound.pause()
    

    顺便说一句,那里没有 .stop() 函数

    【讨论】:

    • 不客气,娑娜。看起来你也在做一个有趣的 chrome 扩展:)
    猜你喜欢
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2011-08-09
    相关资源
    最近更新 更多