Results 1 to 4 of 4

Thread: onClick sound in javascript

  1. #1
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default onClick sound in javascript

    Hi there!

    I'm trying to use a sound file onClick using this helpful script:

    http://www.dynamicdrive.com/dynamici...criptsound.htm

    It works in IE9 and Google Chrome but I can't get it work in Firefox! Any suggestions?

    Here is my test file:

    http://mngaragesales.com/tropetest3.shtml

    Thanks!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    HTML and Javascript don't have convenient ways to play sounds in all browsers. There are a few limited methods, but they'll only work in some browsers.

    Javascript can use an onclick event, though. But you'll need something else to play the sound.

    My recommendation is the following script:
    http://www.schillmania.com/projects/soundmanager2/
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Daniel, I'll look into that program.

    I was able to fix the issue by saving the sound file as an .ogg and having that as an option for the browser to choose from. I didn't realize that mp3s wouldn't work in that script in Firefox.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Having some sort of script that allows multiple formats will be helpful to you. Not all browsers can play all formats, and in fact there isn't always overlap for even one format. A script like soundmanager2 will conditionally choose one format for the current browser (eg, using flash, or using the HTML5 audio element) and save you work.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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