View Full Version : Sounds

May 8th, 2012, 09:23 PM
At a certain moment, a page gives a sound of falling coins. The way it is done at the moment, is by using the html object tag and javascript combination. The first time in one pageload, the moment the sound is heard, the page goes down a height of a <div>. The second time the special effects are heard, this does not happen. Ok, it is solved by playing a 'mute' sound at the onload. But most of the browsers ask, if the user allows to install a plug-in for the sound, and then asks again if the user really allows the installation.

1. Is there a way, to hear the sound without any plug-ins?

2. Is there a way to activate the sound so that the page does not roll down one forth of a inch at the first time the sound is heard, unless playing a 'mute' sound?

3. The current method works, but not in Opera browser. In fact non of the 'w3schools' html sound examples work in Opera, unless a small player is included and the user clicks the 'play'. How to make this, or a better solution to work in Opera?

4. The crazy part is, that the javascript needs to be in <body> section with the current solution to work. I wish a method where the javascript is placed in the <head> section.

Here is quite a few Qs, but the idea is, that there can be a solution which solves all or most of them at ones :)


<span id="sound_element"></span>

<script type="text/javascript">
document.getElementById("sound_element").innerHTML="<object height='0px' width='0px' data='"+"sounds/win.mp3"+"' ></object>";


Philip M
May 9th, 2012, 08:56 AM
Sounds in HTML4 are a nightmare, especially cross-browser. You have discovered some of the insoluble problems. In HTML 5 the <audio> tag will do the job, but of course only modern browsers support it. Things will improve in a few years when HTML 4 is obsolete! :)

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.