JavaScript Tip of the Week for April 29, 1996: Playing Sound in an HTML Document | WebReference

JavaScript Tip of the Week for April 29, 1996: Playing Sound in an HTML Document

JavaScript Tip of the Weekfor April 29, 1996: Playing Sound in an HTML Document

Alleluia! There are a at least three basic ways to play a sound, or any kind of file for that matter, right in an HTML document, no plug-ins required. These examples use a sound file called "alleluia.au", which, if you have a JavaScript compatible browser , is probably downloading right before your eyes as you read. Well anyway, here is the immediate method, this is enacted as soon as the browser loads the page:
    window.location = "alleluia.au"
and here is the delayed method, the number you see is the time it waits before loading the sound file, about 10 seconds:
    setTimeout("location = alleluia.au'", 10000)
My personal favorite is the "when document is done loading" method. First, after the <HEAD> tag, put a <SCRIPT> tag and then:
    function PlaySound(){
        window.location = "alleluia.au"
        }
Then in the BODY tag, put the line
    onLoad = "PlaySound()"
I hope you find this useful, because it can be used for a variety of applications, yet it is soooo simple. The timer one is also great for automatically turning pages, but make sure you give people enough time to download all of document and then read it before turning the page.