It's pretty simple to get started really:

function playSound(url) {
    var a = new Audio(url);
    a.play();
}

Use that as whatever event handler you want for your application. Of course, I'd hope you'd want to do more than just play (for example, maybe pause would be good too?), but it's a start.

Answer from nickf on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › HTMLAudioElement › Audio
HTMLAudioElement: Audio() constructor - Web APIs | MDN
An optional string containing the URL of an audio file to be associated with the new audio element. A new HTMLAudioElement object, configured to be used for playing back the audio from the file specified by url. The new object's preload property is set to auto and its src property is set to ...
Discussions

Play sound on hyperlink? - JavaScript - SitePoint Forums | Web Development & Design Community
Hi guys I’m using this script to play a sound when a link is pressed (I’m viewing it in an iPad): More on sitepoint.com
🌐 sitepoint.com
0
May 27, 2014
html - playing audio in JavaScript from URL with variable - Stack Overflow
LaTeX macro to generate a centered grid of subfigures from a comma list (no gaps, equal widths, auto sublabels 1,2,3…) ... What are the differences between the 1994 and 2003 editions of the Penguin Book of Gay Short Stories? Using self-translated foreign text possibly out of copyright? more hot questions ... To subscribe to this RSS feed, copy and paste this URL ... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to play audio? - Stack Overflow
I am making a game with HTML5 and JavaScript. How could I play game audio via JavaScript? More on stackoverflow.com
🌐 stackoverflow.com
How to play an audio file from an external url using Javascript? - Stack Overflow
I have an app (A) that makes an ajax request to a different app (B) to obtain a link for a wave sound file. Then, I want to use the link to play that sound file directly from my app (A). I tried to More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
mcasimirian.medium.com › playing-audio-on-click-in-your-javascript-app-72aa955068fc
Playing Audio on Click in Your JavaScript App | by Manon Sainton | Medium
May 12, 2021 - The function will trigger the play() method on a “click”, and will play sound clip from the url defined by the sound1 variable on line 2.
🌐
SitePoint
sitepoint.com › javascript
Play sound on hyperlink? - JavaScript - SitePoint Forums | Web Development & Design Community
May 27, 2014 - Hi guys I’m using this script to play a sound when a link is pressed (I’m viewing it in an iPad): <!--[ In the head section of the HTML ]--> <!--audio--> <script type="text/javascript"> function play_single_sound() {…
🌐
Flukeout
flukeout.github.io › simple-sounds
Play Sounds with JavaScript
<script src="sounds.js" type="text/javascript"></script> Then edit the sounds object to add your sounds... "dead" : { url : "sounds/dead.wav" }, "ping" : { url : "sounds/ping.mp3", volume : .5 } The name of the sound above will be "dead". You can add an optional volume property, which can range ...
🌐
W3Schools
w3schools.com › jsref › met_audio_play.asp
HTML DOM Audio play() Method
Tip: Use the controls property to display audio controls (like play, pause, seeking, volume, etc, attached on the audio). ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Go Make Things
gomakethings.com › how-to-play-a-sound-with-javascript
How to play a sound with JavaScript | Go Make Things
July 19, 2021 - Quick aside: autoplaying unwanted background sounds on a webpage can very intrusive and create a terrible user experience. Use this with care! The new Audio() constructor lets you create a new HTMLAudioElement. Pass in the URL of the audio file ...
Find elsewhere
🌐
Dobrian
dobrian.github.io › cmp › topics › sample-recording-and-playback-with-web-audio-api › 1.loading-and-playing-sound-files.html
Loading and Playing Sound Files
So rather than load all of our audio files at once, we can instead load each audio file asynchronously, meaning that we will only grab it from the server when we explicitly ask for it. In JavaScript, you can make asynchronous requests to the server with XMLHttpRequest.
🌐
npm
npmjs.com › package › play-audio-url
play-audio-url - npm
var playAudioURL = require('play-audio-url'); playAudioURL({ url: 'https://whatever.com/some-sound.ogg' }, onPlay); // You can also pass sampleRate here. // e.g.: { url: 'https://o.k/guy.mp3', sampleRate: 22050 } // playAudioURL passes back ...
      » npm install play-audio-url
    
Published   Mar 03, 2019
Version   1.0.1
Author   Jim Kang
🌐
YouTube
youtube.com › watch
How to Play Audio with JavaScript - YouTube
A simple tutorial.The link to the audio file I used:https://vincens2005.github.io/vr/Nyan Cat [original].mp3http://cukmekerb.gq/The link to my merch:shop...
Published   June 10, 2018
🌐
YouTube
youtube.com › watch
How To Play Audio From An External URL On The Click Of A Button In ReactJS - YouTube
Please don't forget Like, Comment and Subscribe if you're new!Hope y'all enjoyed this tutorial this was a suggestion. We will learn how to play any audio cli...
Published   January 16, 2020
🌐
Medium
noaheakin.medium.com › adding-sound-to-your-js-web-app-f6a0ca728984
Adding Sound to Your JS Web App. If you are looking to add another layer… | by Noah Eakin | Medium
November 3, 2020 - Remember, if you want to have music or audio play on your web app you will likely have to tie it to a click event somewhere on the page. If you are using a local audio file, make sure you are using the correct file path in your Audio() constructor. If a desired sound is not playing, use your browser’s native development tools to check that the file path in your GET request is displaying as intended
🌐
JavaScripter
javascripter.net › faq › sound › play.htm
JavaScript: Playing Sound
Playing Sound from JavaScript JavaScript FAQ | JavaScript Sound FAQ · Question: How do I write a JavaScript function that plays a sound file
🌐
Reddit
reddit.com › r/html › how to play an audio when clicking on a link, or just clicking in general?
r/HTML on Reddit: How to play an audio when clicking on a link, or just clicking in general?
July 11, 2024 -

I apologize for the lack of any code here, I am extremely new to HTML and am trying to create a personal website. I want to play a silly sound effect for when you click on anything on this page, but i can't seem to find suitable code, or just code that makes any sense to me.

I want the audio to be able to replay, not take you to the source of the audio, y know, just a simple sound effect.

🌐
Processing Forum
forum.processing.org › two › discussion › 26096 › playing-a-sound-from-a-url-from-processing-js
Playing a sound from a URL from Processing JS - Processing 2.x and 3.x Forum
January 23, 2018 - I have found it is possible taking advantage of this from near your link http://processingjs.org/articles/jsQuickStart.html#mixingjsandprocessing · I just add e.g. var audio = new Audio('https://upload.wikimedia.org/wikipedia/commons/6/6e/(Audio_Bahasa_Melayu)_ibu.ogg'); audio.play(); Thanks. KevinWorkman · January 2018 Answer ✓ · Note that this requires an external .ogg file. I thought you were looking for something like a sound synthesizer, which I believe would require a JavaScript library.
🌐
CodePen
codepen.io › SitePoint › pen › JRaLVR
Playing an MP3 file with the Web Audio API
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.