6

I want to change the src attribute of a tag using javascript and a button :

<audio id="playme" src="" controls="controls">Your browser...</audio>

And a little further down the page :

<input type="button" style="font-size: 10px;"
        OnClick="document.getElementById('playme').src='snd/SOUND.WAV';"
        value="Listen">

It seems to just do nothing. Anyone has a clue ? Thanks a million

Using Firefox 3.6 on Xubuntu 10.10

EDIT : it seems to work on Chrome but Firefox doesn't like it. Should I report a bug ? Do you know a way to bypass that ?

1 Answer 1

16

I believe you have to tell the browser to load the new file when you change the src attribute, by calling load:

var playme = document.getElementById('playme'); playme.src='snd/SOUND.WAV'; playme.load();
Sign up to request clarification or add additional context in comments.

1 Comment

This works great for .wav and .mp3 files. .ogg files work on a PC running Chrome, Firefox or Safari. However mobile safari(iOS) and Android (Firefox and Chrome fail to see the sounds. can the "type" be updated this way as well? like type="xx" in the <Audio> tags?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.