Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Click image for sound?

    What is the correct code to make a sound play every time you click a certain image? All the codes I've found online aren't working, or I'm not inputting something correctly..

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,146
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Quote Originally Posted by kg67 View Post
    What is the correct code to make a sound play every time you click a certain image? All the codes I've found online aren't working, or I'm not inputting something correctly..
    Cross-browser sound rendering is a nightmare.

    Google for example:-

    http://www.phon.ucl.ac.uk/home/mark/audio/play.htm

    http://www.javascripter.net/faq/sound/play.htm


    I've just watched the replay and there is absolutely no doubt - it's inconclusive. - Commentator BBC Radio 1

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Cross-browser sound rendering is a nightmare.

    Google for example:-

    http://www.phon.ucl.ac.uk/home/mark/audio/play.htm

    http://www.javascripter.net/faq/sound/play.htm
    The website is most likely only going to be viewed by a small group of people for a class, on Chrome and Safari... I don't know enough HTML and basically no javascript to figure it out myself.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,146
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Quote Originally Posted by kg67 View Post
    The website is most likely only going to be viewed by a small group of people for a class, on Chrome and Safari... I don't know enough HTML and basically no javascript to figure it out myself.
    Well, that makes it harder! Presumably you would not attempt to service or repair a machine or appliance without any experience or understanding of how it worked.

    If all your users will be using only the most modern browsers which support HTML5, then use the <audio> tag and follow the instructions at:-

    http://www.phon.ucl.ac.uk/home/mark/audio/play10.htm

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,400
    Thanks
    11
    Thanked 595 Times in 575 Posts
    Quote Originally Posted by Philip M View Post
    Well, that makes it harder! Presumably you would not attempt to service or repair a machine or appliance without any experience or understanding of how it worked.
    yeah, it's sooooo hard:

    Code:
     
    
    
    <html>
      <img src="http://www.codingforums.com/image.php?u=186&dateline=1284371569"  onclick="audio.play()" />
      <script>
        audio=new Audio("http://archive.org/download/tsp1997-01-08.flac16/tsp1997-01-08d1t13.ogg");
      </script>
    </html>
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

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