7

Is it possible to play audio without the audio tag and just using javascript?

I'm injecting script through a tinyMce editor since I don't have access to a site's backend and it doesn't support the audio tag for a client. She just wants a simple sound when you hover over an image. I have it all setup however, the restriction of not having an audio tag is tripping me up.

I am hosting the audio files on a remote site since I cannot upload them here. Is there perhaps a way to leverage that remote site? I've never run into this issue before and can't really find anything on it.

zazvorniki
  • 3,512
  • 21
  • 74
  • 122
  • Have you tried anything yet? If so please edit your question and include your attempt(s). – NewToJS Mar 04 '16 at 00:08
  • The [Web Audio API](http://www.html5rocks.com/en/tutorials/webaudio/intro/) might be a good place to start. – nathansnider Mar 04 '16 at 00:11
  • @nathansnider, That's interesting I'll have to look at that. It seems a little too complex for what I'm trying to do here though. – zazvorniki Mar 04 '16 at 00:20

1 Answers1

15

You can use this:

mySound = new Audio('sound.mp3');
mySound.play()

Here is a link to its specification - HTMLAudioElement

Eni Arinde
  • 555
  • 5
  • 6
  • Thank you so much! I've never seen it done this way, but I don't have much experience with audio on the web. I generally try to avoid it...memories of audio play songs haha – zazvorniki Mar 04 '16 at 00:19