2

I want to play sound onclick event. I have code in which i can play sound in Firefox and other browser but not in safari. Below is the code. Safari gives me the error like "thissound.Play" [undefined ] is not a function.

function EvalSound(soundobj) {
  var thissound= eval("document."+soundobj);
  thissound.Play();
}

<embed src="namaste_london01(www.songs.pk).mp3" autostart=false width=0 height=0 name="sound1"
enablejavascript="true">

<a href="#" onClick="EvalSound('sound1')"> Play </a>

Thanks in advance.

jwueller
  • 30,582
  • 4
  • 66
  • 70
satishdas
  • 65
  • 3
  • 10

1 Answers1

0

jQuery has some great audio plugins. It also means you can get rid of nasty onclick attributes, and so keep all your javascript between the script tags.

Nathan MacInnes
  • 11,033
  • 4
  • 35
  • 50
  • Your JavaScript should not be between ` – jwueller Nov 19 '10 at 10:52
  • @Elusive - depends - no point in making another connection to the server for 5 lines of script. However, there comes a point, when yes, putting it in a separate file is definitely the way to go :) – James Westgate Apr 01 '11 at 09:21