How to play a notification sound on websites?

前端 未结 11 1530
生来不讨喜
生来不讨喜 2020-11-28 01:32

When a certain event occurs, I want my website to play a short notification sound to the user.

The sound should not auto-start (instantly) when the

11条回答
  •  星月不相逢
    2020-11-28 02:08

    var audio = new Audio('audio_file.mp3');
    
    function post()
    {
      var tval=document.getElementById("mess").value;   
      var inhtml=document.getElementById("chat_div");
      inhtml.innerHTML=inhtml.innerHTML+"

    Me:-"+tval+"

    "; inhtml.innerHTML=inhtml.innerHTML+"

    Demo:-Hi! how are you

    "; audio.play(); }

    this code is from talkerscode For complete tutorial visit http://talkerscode.com/webtricks/play-sound-on-notification-using-javascript-and-php.php

提交回复
热议问题