Question:
Dear Dr. Website:
How do you embed multiple audio files and allow the
user to choose what song they want to hear?
Thanks
Answer:
You'd use something like this:
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Nicholas Loar -->
<!-- Web Site: http://www.cass.net/~anarchy -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
songNum = new Array();
songNum[0] = "#";
songNum[1] = "new.mid";
songNum[2] = "spice.mid";
songNum[3] = "ole.mid";
var music = null;
var track = 0;
var ver = navigator.appName;
function audioCheck(plugName) {
for (var i = 0; i < navigator.plugins.length; i++) {
if (navigator.plugins[i].name.toLowerCase() == plugName.toLowerCase())
{
for (var j = 0; j < navigator.plugins[i].length; j++) {
if (navigator.plugins[i][j].enabledPlugin) {
return true;
}
}
return false;
}
}
return false;
}
function chooseSong(s) { // ie
track = s.options[s.selectedIndex].value;
if (ver == "Microsoft Internet Explorer") {
document.all.music.src = songNum[track];
} else {
songPlay('play');
}
}
function songPlay(cmd) { // netscape
if (audioCheck("LiveAudio")) {
if (cmd == 'play') {
document.musicSource.play(false, songNum[track]);
}
} else {
alert("You Do Not Have The Correct Plugin");
}
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<center>
<form name=choose>
<select size=1 name=track
onChange="chooseSong(this);">
<option value="0">Click For Midi</option>
<option value="1">New</option>
<option value="2">Spice</option>
<option value="3">Ole</option>
</select>
</form>
<script language="JavaScript">
<!-- Begin
var ver = navigator.appName;
if (ver == "Microsoft Internet Explorer") {
document.write('<bgsound src="#" ID=music loop=1
AUTOSTART=true>');
} else {
document.write('<embed type="audio/midi"
src="new.mid" AUTOSTART=false
hidden=false VOLUME="90" name="musicSource" MASTERSOUND></EMBED>');
}
// End -->
</script>
</center>
Of course you'll need to change the midi file names to the file you wish to
make available to your site's visitors.
--Dr.Website
Question:
Dear Dr. Website:
How can I calculate the weight of my pages? Is it
as simple as adding the file size of the page plus the file size of every image/graphic contained within it? Keep up the great service. Your the best.
Thanks!
Answer:
Thanks for the kind words! As for your question, you've already got the answer--you just add up all the elements of your page: the page itself, the images on the page, the CSS file if you're using one, any external JavaScripts the page may be calling, any Java applets on the page, etc. It'd be something like this:
page - 15k
graphics - 42k
CSS file - 4k
java applet - 30k
total: 91k
Thanks,
--Dr.Website
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~