Created
March 19, 2014 17:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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