html - Playing sound with JavaScript -


No matter what I do, I can not find it to play sound in Firefox or IE or Chrome for that matter.

  & lt; Html & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" & gt; Function play () {var embed = document.createElement ('object'); Embed.setAttribute ('src', 'c: \\ test.wav'); Embed.setAttribute ('hidden', true); Embed.setAttribute ('autostart', is true); Embed.setAttribute ('enable javascript' is true); Document.childNodes [0] .appendChild (embedded); } // -> & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body onload = "play ();" & Gt; & Lt; / Body & gt; & Lt; / Html & gt;  

Try to use this modified version of the function play ()

  function play () {var embed = document.createElement ('object'); Embed.setAttribute ('type', 'audio / wav'); Embed.setAttribute ('data', 'c: \ test.wav'); Embed.setAttribute ('autostart', is true); Document.getElementsByTagName ('body') [0] .appendChild (embedded); }  

The problem with your code was that you were using the src attribute, which is & lt; Embed & gt; Tag Instead, & lt; Object & gt; Use the data attribute for Tag



If you are trying to get the most compatibility from this, then you should consider adding an object tag as an optional tag. The way this works, it is like this:

   & Lt; / Object & gt;  

This works similar to the Noscript tag, where the old broues that do not support object tag resorts on embed tags.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -