最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ajax - Wordpress sound bell when new data will add

programmeradmin2浏览0评论

I'm working to add a bell notification when any new data row inserted in the attached table this will give sound bell. (very similarly when we receive new message we get notification sound bell on Facebook)

I'm able to make the function of the bell this below

function ding() {
    var bell = new  Audio("/public/sounds/Notification%201.mp3");  
    bell.play();
}

now the problem I'm facing the bell not working when new data row inserted i have tried many codes like below

$("#theTable").on("change", function() {
    function ding() {
    var bell = new  Audio("/public/sounds/Notification%201.mp3");  
    bell.play();
}
});

I'm working to add a bell notification when any new data row inserted in the attached table this will give sound bell. (very similarly when we receive new message we get notification sound bell on Facebook)

I'm able to make the function of the bell this below

function ding() {
    var bell = new  Audio("https://facebook.design/public/sounds/Notification%201.mp3");  
    bell.play();
}

now the problem I'm facing the bell not working when new data row inserted i have tried many codes like below

$("#theTable").on("change", function() {
    function ding() {
    var bell = new  Audio("https://facebook.design/public/sounds/Notification%201.mp3");  
    bell.play();
}
});

Share Improve this question asked Jan 19, 2020 at 17:14 Aadii MughalAadii Mughal 1711 gold badge1 silver badge9 bronze badges 3
  • 1 I doubt it that the 'change' event is a valid one for your situation. You should try to add a function that reads the total amount of rows and when that changes it will ring the bell. – Cornel Raiu Commented Jan 19, 2020 at 18:34
  • total quantity of tables row? can u advice me further how i can check total row in table – Aadii Mughal Commented Jan 20, 2020 at 8:14
  • 1 Please post the HTML that is used to build the table so that I can write the JS for doing that. – Cornel Raiu Commented Jan 20, 2020 at 8:21
Add a comment  | 

1 Answer 1

Reset to default -1

There may be browser restrictions preventing autoplaying audio, see this answer https://stackoverflow/questions/53058421/local-variable-audio-in-object-method-not-playing

You can see this in your browser developer tools console, there will be error like this NotAllowedError: The play method is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

If this sound notification is needed only for some specific users, you can change their browser policy to allow autoplay.

发布评论

评论列表(0)

  1. 暂无评论