Answer the question
In order to leave comments, you need to log in
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
also possible like this:
var audioAlert = new Audio("http://www.mult.ru/rings/night_elf_track.mp3");
audioAlert.onplaying = function () {
alert("hi");
}
audioAlert.play();
Apparently like this:
{
document.getElementById('xyz').play();
alert("Thank you!");
}
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 questionAsk a Question
731 491 924 answers to any question