★ wanayoo — archive 1999 http://techweb3.web.cerf.net/tools/java/java44h.htmlNouvelle recherche | Portail wanayoo
Click here for Digital Alpha Server


Feb 15, 1997
Playing Sound On Demand

The addition of sound to an HTML page enhances the interactive experience. Using just a few lines of JavaScript code, you can play sound when a document is loaded or exited or when the user clicks on a link. The following example illustrates using an image as a link for playing sound on demand.

<HTML>
<HEAD>
<TITLE>Playing Sound On Demand</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function play(){
window.location = "sample.au"
}
</SCRIPT>
</HEAD>
<body bgcolor=ffffff>
<h2>Playing on-demand sound:</h2>
<b>Please click on the image below</b><br>
<a href="javascript:play()"><img SRC="/old?u=http%3A%2F%2Ftechweb3.web.cerf.net%2Ftools%2Fjava%2Fimages%2Fsound.jpg&y=1999"
border=0></a>
</body>
</HTML>
Listing 1.7


Output from listing 1.7

Clicking on the image calls the function play() which is linked by the function javascript:play(). The play function uses the location property of the document object and simply points to the sound file.

tip You can use the same code to play other multimedia files, such as a Shockwave movie. Just replace the "sample.au" with a different filename (e.g."sample.dcr").

Sponsored By:
Click here for Novell Brainshare

Hands-On
3-D Cards
Firewalls
HTML Authoring
Java
+ JavaScript Feature
+ Cool Java Apps
+ Brewing Your Own
+ Applet Tutorial
+ JavaScript Tutorial
+ Beyond the Browser
+ Java Resources
+ Java Bookshelf
Netscape Plug-ins
Offline Web Agents
Search Engines
Utilities
Web Animation
Web Audio
Web Video
Executive Briefing
ISPs
Net PCs
Windows NT
ActiveXpress
Controls, How-Tos, Reviews

The Comprehensive Guide to Seminars, Events & Co

TechWeb HomeTechSearchCMP's WebsitesTechCareerTechCalendarTechWeb InfoSite Map