2010-11-19 2 views
2

소리 onclick 이벤트를 재생하고 싶습니다. 파이어 폭스와 다른 브라우저에서는 사파리가 아닌 사운드를 재생할 수있는 코드가 있습니다. 다음은 코드입니다. 사파리는 "thissound.Play" [undefined ] is not a function과 같은 오류를 표시합니다.사파리에서 javascript를 사용하여 사운드 재생

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> 

미리 감사드립니다.

+2

왜 'eval'을 사용하고 있습니까? 단순히'document [ 'sound1']. Play()'를 사용할 수 있습니다. – jwueller

답변

0

jQuery에는 멋진 오디오 플러그인이 있습니다. 또한 불쾌한 onclick 속성을 없애고 스크립트 태그 사이에 모든 자바 스크립트를 유지할 수 있음을 의미합니다.

+0

JavaScript는 실제로 '