Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

play sound javascript

var audio = new Audio("folder_name/audio_file.mp3");
audio.play();
Comment

javascript play sound onclick

var audio = new Audio("soundfile.wav");

document.onclick = function() {
  audio.play();
}
Comment

sound on click javascript

<button onclick="playSound()">Play</button>

<script>
let playSound = () => new Audio("src.mp3").play();
</scirpt>
Comment

play sound in javascript

<script>
function play() {
  var audio = new Audio('https://interactive-examples.mdn.mozilla.net/media/examples/t-rex-roar.mp3');
  audio.play();
}
</script>
<button onclick-"play();">PLAY MY AUDIO</button>
Comment

javascript click sound

<audio id="audio" src="http://www.soundjay.com/button/beep-07.wav" autoplay="false" ></audio>
<a onclick="playSound();"> Play</a>
<script>
  function playSound() {
  var sound = document.getElementById("audio");
  sound.play();
}
</script>
Comment

javascript audio play on click

<!doctype html>
<html>
  <head>
    <title>Audio</title>
  </head>
  <body>

    <script>
      function play() {
        var audio = document.getElementById("audio");
        audio.play();
      }
    </script>

    <input type="button" value="PLAY" onclick="play()">
    <audio id="audio" src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"></audio>

  </body>
</html>
Comment

Javascript Audio Play on click


JavaScript

function playAudio(url) {
  new Audio(url).play();
}

HTML

<img src="image.png" onclick="playAudio('mysound.mp3')">

Supported in most modern browsers and easy to embed into HTML elements.
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript change long digit ot k,m 
Javascript :: javascript get all script tags on page 
Javascript :: how to append only once in jquery 
Javascript :: sleep sort 
Javascript :: golang convert json string to map 
Javascript :: express get cookie 
Javascript :: node pre gyp error 
Javascript :: afficher un div qui etait cache en javascript 
Javascript :: get guild by id discord.js 
Javascript :: jquery mouseup javascript 
Javascript :: convert dict to json python 
Javascript :: lodash combine permissions 
Javascript :: solid icons in next js 
Javascript :: Access-Control-Allow-Origin 
Javascript :: translatex in javascript 
Javascript :: javascript merge two lists without duplicates 
Javascript :: js password validation regex 
Javascript :: requirenativecomponent rnsscreen was not found in the uimanager 
Javascript :: javascript emit beep 
Javascript :: react native linking phone call 
Javascript :: javascript custom events with data 
Javascript :: convert json string to json object in laravel 
Javascript :: remove item jquery 
Javascript :: run javascript from uri 
Javascript :: value from getelementbyid 
Javascript :: javascript change image src 
Javascript :: javascript style text decoration 
Javascript :: moment get time am pm 
Javascript :: cypress enter 
Javascript :: js array into object 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =