I can preload images easily thanks to the onload
function. But it doesn\'t work with audio. Browsers like Chrome, Safari, Firefox, etc. don\'t support the
//Tested on Chrome, FF, IE6
function LoadSound(filename) {
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("load-sound").innerHTML = '';
}
}
xmlhttp.open("GET", filename, true);
xmlhttp.send();
}
Reference
- http://sharkysoft.com/tutorials/jsa/content/048.html
- jQuery: How do you preload sound?
- http://jsarchive.8m.com/Main/audio.html