Skip to content

Instantly share code, notes, and snippets.

@amundo
Created March 19, 2014 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amundo/9646534 to your computer and use it in GitHub Desktop.
Save amundo/9646534 to your computer and use it in GitHub Desktop.
JS function to change links like <a href="something.wav">sound</a> so that they play when clicked
/*
There are a lot of pages like:
http://titus.uni-frankfurt.de/ld/
Which have links to .wav files. It's annoying to have to change
context, load "QuickTime", blah blah, and to lose the context
of the name of the link when you're listening to it.
The following function creates an Audio object which plays when
the link is clicked.
*/
var a = [... document.querySelectorAll('a[href$="wav"]')].forEach(
function(a){
var audio = new Audio();
audio.src = a.href;
a.addEventListener('click', function(ev){
ev.preventDefault();
audio.play();
})
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment