I would like the popup.html to play a sound from a file when a user clicks on an image and stop the sound when the user clicks the same image again.
When I use the code below, the sound begins playing the moment the popup.html is opened and not by the 'addEventListener'.
options.js
var eggAudio = new Audio("sound.mp3");
eggAudio.loop = true;
document.getElementById('egg1').addEventListener('click', eggAudio.play() );
popup.html
<div id='egg'><img id="egg1" src='img/egg.png'/></div>
<script src="options.js"></script>
Aucun commentaire:
Enregistrer un commentaire