Skip to content

Instantly share code, notes, and snippets.

@mikedugan
Created November 7, 2013 14:32
Show Gist options
  • Select an option

  • Save mikedugan/7355491 to your computer and use it in GitHub Desktop.

Select an option

Save mikedugan/7355491 to your computer and use it in GitHub Desktop.
plays an audio element using HTML audio tags
function playAudio(audio){
document.getElementById(audio).play();
}
/*
---------Add the following to your HTML doc (somewhere above the JavaScript include) --------
<audio id="audio" src="audio.wma" preload="auto" controls></audio>
--------Add this as an event handler to your documents opening <body> tag----------
onload="playAudio('audio')"
---------In your HTML <head> element, add the following ------------
<script src="scripts/audio.js" >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment