Results 1 to 2 of 2

Thread: Trying to play wav file when img or button clicked

  1. #1
    Join Date
    Feb 2011
    Kansas City, Mo

    Trying to play wav file when img or button clicked

    Hi everybody, I just registered here tonight.
    I'm having a problem that I thought would be simple, but it's driving me crazy!
    I simply want to play a short .wav sound when a button or image is clicked. I have one that plays once when the page opens, but I don't want that. I want the sound to wait for the OnClick.
    This script I have looks right, but I'm new and don't fully understand how to go about this. If anyone would help me out here, I would solve the Middle East trouble, eliminate the National debt, and find jobs for all the unemployed!
    Thanks for any guidance, JD ps. I use Chrome & IE
    <style type="text/javascript">

    function EvalSound(soundobj) {
    var thissound=document.getElementById(soundobj);



    <input type="button" value="Play Sound" onClick="EvalSound('/pages/laugh.wav')">

    <!-- sound file is laugh.wav ,it is in the same folder as this page ( /pages/pgtest9.html )--!>
    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SIMBAR={5DC47607-819F-11DF-897C-00904BDA636E}; GTB6.6; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; yie8; AskTbNG2V5/
    Timestamp: Sat, 12 Feb 2011 08:27:55 UTC

    Message: Object expected
    Line: 21
    Char: 1
    Code: 0
    URI: http://mountaindream.freeoda.com/pages/pgtest9.html

  2. #2
    Join Date
    Jul 2008
    urbana, il
    for chrome and IE9:
    function playme (url){
        var audio=document.createElement("audio");

    i went ahead and cooked up an xbrowser version that works in IE, provided they have WindowMedia installed, which should be most IE machines.
    If anyone out there can improve the IE code, please post amended code.

    (tested: FF4, IE7, CH9)
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    <html xmlns="http://www.w3.org/1999/xhtml">
    	<title>testing ability to play wav files</title>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <input value='play' type='button'  onclick="playme(audioURL)" />
    <script type='text/javascript'>
    function playme (url){
     if("v"=="\v"){ //IE:
        var audio=document.createElement("div");
        audio.innerHTML= '<object height="10" width="1" style="left:-9999px; height: 0px; width: 0px;" \
    		<PARAM name="autoStart" value="TRUE"/>\n\
    		<PARAM name="UIMode" value="mini"/>\n\
    		<PARAM name="URL" value="***" />\n\
    	</object>'.replace("***", url);
        var audio=document.createElement("audio");
    }//end playme
    Last edited by rnd me; 02-13-2011 at 04:40 PM.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles