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("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();
}
});

table image

  • 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 Jan 19 at 18:34
  • total quantity of tables row? can u advice me further how i can check total row in table – Aadii Mughal Jan 20 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 Jan 20 at 8:21
-1

There may be browser restrictions preventing autoplaying audio, see this answer https://stackoverflow.com/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.

| improve this answer | |
  • no friend. i'm still struggling to add bell function it's not working. – Aadii Mughal Jan 20 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.