Different Ways to Play a Sound from a Web Page6. Using Dynamic HTMLDynamic HTML allows you to use JavaScript to write new HTML code into your page and let it be interpreted by the browser. The trick to using dynamic HTML for sound replay is to write into a region of the document the HTML of an embedded sound set to automatically start replay on load. Here we are going to use a
function DHTMLSound(surl) {
document.getElementById("dummyspan").innerHTML=
"<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}
We can now create the dummy span region and just pass the URL of the sound file to the function to play it:
<span id=dummyspan></span>
<form>
<input type="button" value="Play Sound" onClick="DHTMLSound('success.wav')">
</form>
| ||