M
M
Markusan2018-08-17 23:35:43
JavaScript
Markusan, 2018-08-17 23:35:43

Can I make an alert with sound in JS?

Greetings. Can it be made to be alert('');accompanied by sound? The difficulty is that I don’t have the ability to connect third-party js libraries, because everything happens in the browser console (I’m trying to write a very simple web monitor in js)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Martovitskiy, 2018-08-18
@Markusan

also possible like this:

var audioAlert = new Audio("http://www.mult.ru/rings/night_elf_track.mp3");
audioAlert.onplaying = function () {
  alert("hi");
}
audioAlert.play();

Y
Yuri, 2018-08-18
@modestguy

Apparently like this:

{
    document.getElementById('xyz').play();
    alert("Thank you!");
}

X
xmoonlight, 2018-08-18
@xmoonlight

Get, sign (checked!):

<script>
var oa=window.alert;
startFrom=10; //sec
loaded=false;

  var audioAlert = new Audio("http://www.mult.ru/rings/night_elf_track.mp3");
  audioAlert.currentTime = startFrom;
  audioAlert.addEventListener('loadeddata', function() {
    if(audioAlert.readyState >= 2) {
        loaded=true;
    }
  });

window.alert = function (message) {
  if (loaded) {
      if(audioAlert.paused) {
         audioAlert.play();
         oa&oa(message);
         audioAlert.pause();
         audioAlert.currentTime = startFrom;
      }
  } else {oa('not loaded!');}
};
</script>
<div onclick=alert('hi');>Жми!</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question