dresdena1
asked on
Play sound when a link is clicked
EE,
I am trying to find code for JavaScript that will play a sound (.wav file) when a link is clicked. I do not want the sound to play when the page loads and I am only going to associate it with a single link on a page.
I would like it to play in IE and FireFox, but if I can get it work only in IE that would fine.
Any help would be greatly appreciated.
dresdena1
I am trying to find code for JavaScript that will play a sound (.wav file) when a link is clicked. I do not want the sound to play when the page loads and I am only going to associate it with a single link on a page.
I would like it to play in IE and FireFox, but if I can get it work only in IE that would fine.
Any help would be greatly appreciated.
dresdena1
ASKER
spprivate,
Thanks for the quick response.
I will already be using the link to go to another page.
dresdena1
Thanks for the quick response.
I will already be using the link to go to another page.
dresdena1
Try this
-------------------------- ----------
function DHTMLSound(surl) {
document.getElementById("d ummyspan") .innerHTML =
"<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}
<span id='dummyspan'></span>
<form>
<img src="play.gif" onClick="DHTMLSound('succe ss.wav')">
</form>
-------------------------- ---------- ---
This should work in IE and FF
--------------------------
function DHTMLSound(surl) {
document.getElementById("d
"<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}
<span id='dummyspan'></span>
<form>
<img src="play.gif" onClick="DHTMLSound('succe
</form>
--------------------------
This should work in IE and FF
ASKER
sinoj,
I am trying to get this to work on a horizontal line of text links. I believe that the form tag is causing a line break.
To try to get sound to play, I enclosed the <a href in the form tags and replaced the img src with a href and then put the DHTMLSound with the sound file that I am interested in playing.
It didn't work.
Do I need to enclose the function in <script> tags?
It showed through the browser so I enclosed in <script> tags to hide it and I also tried putting it in the <HEAD> section.
I am still unable to get any sound.
Here is my last try:
<<
<script>
function DHTMLSound(surl') {
document.getElementById("d ummyspan") .innerHTML =
"<embed src='"+surl'+"' hidden=true autostart=true loop=false>";
}
</script>
<span id='dummyspan'></span>
<form>
<a href="race_schedule.html" onClick="DHTMLSound('cowbe ll.wav')"> Races</a>& nbsp;  ;
</form>
>>
Any ideas?
Thanks very much
dresdena1
I am trying to get this to work on a horizontal line of text links. I believe that the form tag is causing a line break.
To try to get sound to play, I enclosed the <a href in the form tags and replaced the img src with a href and then put the DHTMLSound with the sound file that I am interested in playing.
It didn't work.
Do I need to enclose the function in <script> tags?
It showed through the browser so I enclosed in <script> tags to hide it and I also tried putting it in the <HEAD> section.
I am still unable to get any sound.
Here is my last try:
<<
<script>
function DHTMLSound(surl') {
document.getElementById("d
"<embed src='"+surl'+"' hidden=true autostart=true loop=false>";
}
</script>
<span id='dummyspan'></span>
<form>
<a href="race_schedule.html" onClick="DHTMLSound('cowbe
</form>
>>
Any ideas?
Thanks very much
dresdena1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sinoj,
Perfect! Thanks very much!
dresdena1
Perfect! Thanks very much!
dresdena1
<A HREF = "mymusic.wav" >Listen Sound </A>
Thats it