View Full Version : Click sound effect OK for Firefox but not IE

01-02-2012, 08:20 AM
this is my first forum post. I'm developing a website for use in Thai schools in which clicking on link (at the beginning of a line of English text) starts a sound file (ogg or mp3).

I've been using the Mouseover/Click sound effect script from by JavaScript Kit (www.javascriptkit.com). It works as designed in Firefox and Opera but doesn't in IE8. The script relies on HTML5 functionality so it should be compatible with IE8 (so I understand).

I'm using Ubuntu 10.04 with Windows XP SP3 as the guest OS on VirtualBox. it seems to be a problem specific to IE8 (perhaps, not too surprising!) since the script works OK for Firefox and Opera.

Here is the script

var html5_audiotypes={ //define list of audio file extensions and their associated audio types. Add to it if your specified audio file isn't on this list:
"mp3": "audio/mpeg",
"mp4": "audio/mp4",
"ogg": "audio/ogg",
"wav": "audio/wav"
function createsoundbite(sound){
var html5audio=document.createElement('audio')
if (html5audio.canPlayType){ //check support for HTML5 audio
for (var i=0; i<arguments.length; i++){
var sourceel=document.createElement('source')
sourceel.setAttribute('src', arguments[i])
if (arguments[i].match(/\.(\w+)$/i))
sourceel.setAttribute('type', html5_audiotypes[RegExp.$1])
return html5audio
return {playclip:function(){throw new Error("Your browser doesn't support HTML5 audio unfortunately")}}
//Initialize two sound clips with 1 fallback file each:
var a=createsoundbite("chot_pic01.ogg", "chot_pic01.mp3")
var b=createsoundbite("chot_pic02.ogg", "chot_pic02.mp3")

I only know a little Javascript at present, so I would be thankful of any help

01-02-2012, 09:20 AM
I suppose I should mention that the audio files triggered by the onclick events contain spoken English corresponding to the text on the screen.

01-02-2012, 10:29 AM
HTML5 <audio> tag is only supported for IE>8

01-02-2012, 10:53 AM
Thanks, I'll upgrade IE.

01-13-2012, 07:09 AM
Unfortunately, there are a massive number of IE<9 users out there.

I've looked around for tutorials or examples of onclick actuating audio files relevant to pre-html5. I'm not talking about a single button or link controlling a single file. The functionality I'm looking for as I mentioned is for multiple audio files to be actuated by individual links specific to each file.

Any general pointers as to how I might approach this would be very much appreciated. I have a background in C programming (not extensive but enough to orient me to Javascript) so I'm not exactly starting from square one.