Wednesday, 15 April 2015

jquery - playing a sound through javascript when button has certain value -


If a button has a fixed value, I need a Javascript solution to play a specific sound

I Using jquery or javascript has not tried this kind of functionality. How can someone guide me?

Find a sound you like (for example).

Add a & lt; Audio & gt; Place the element
Receive your audio element and call play () :

  document.getElementById ('yourAudioTag'). Play ();   

Check out this example:

There are some good things that you can do, such as load () , ) , and some other properties of the audio element.

When you really want to play this audio element, then read the text of the button depending on you and compare it to "no" if you want.

Alternatively

Sound Manager2 API makes it easy to use which allows sound played in any modern browser including IE 6+ The browser can be supported if the browser does not support HTML5. If you do not want hard HTML5 and no flash, then there is a setting for it, like Flash = false

This iPad, iPhone (iOS 4) and other HTML5-enabled devices + 100% Supports Flash Free Audio

Simples as Usage:

  & lt; Script src = "soundmanager2.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; // To find Flash SWF, if necessary ... soundManager.url = '/ path / to / swf-files /'; SoundManager.onready (function () {soundManager.createSound ({id: 'mySound', url: '/path/to/an.mp3'}) ... and play this sound manager play ('mySound') ;});   

Here's a demo in action:

No comments:

Post a Comment