Sounds on JavaScript Events


The following are some examples of JavaScript event handlers used to play sounds. You should have also heard a sound play when this page loaded; you'll hear another one when you unload this page.
Click here for a sound

 

  • Source

    <HTML>
    <HEAD>
    <TITLE>Sounds on JavaScript Events</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    function playsound(sfile) {
    // load a sound and play it
    window.location.href=sfile;
    }
    </SCRIPT>
    </HEAD>
    <BODY
      onLoad="playsound('zap.wav');"
      onUnload="playsound('click.wav');" >
    <H1>Sounds on JavaScript Events</H1>
    <HR>
    The following are some examples of JavaScript event handlers used to
    play sounds. You should have also heard a sound play when this page
    loaded; you'll hear another one when you unload this page.
    <HR>
    <a href="#" onClick="playsound('zap.wav');">
     Click here for a sound
    </a>
    <FORM NAME="form1">
    <INPUT TYPE="button" VALUE="Button to Play a Sound"
    onClick="playsound('click.wav');">
    </FORM>
    </BODY>
    </HTML>