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

how to play sound on load js

var sample = document.getElementById("foobar");
sample.play();
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

how to play sound on load js

 <audio id="foobar" src="yoursample.ogg" preload="auto"> 
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

js play sound

const sound = require("sound-play");
sound.play("file.mp3");
Comment

how to play sound on load js

 #foobar { display: none }
Comment

PREVIOUS NEXT
Code Example
Javascript :: refresh div jquery 
Javascript :: javascript parse and validate json 
Javascript :: ng generate component in folder 
Javascript :: reactjs absolute import 
Javascript :: redirect not found in react-router-dom 
Javascript :: how to create a new react native project 
Javascript :: query selector click event 
Javascript :: js settimeout 
Javascript :: how to replace commas with nothing in javascript 
Javascript :: javascript scroll down 
Javascript :: how to swap two elements in an array js 
Javascript :: remove stack header bottom line react native 
Javascript :: socket io broadcast to room 
Javascript :: index.js vs main.js 
Javascript :: if odd js 
Javascript :: documentready 
Javascript :: javascript to convert rgb to hsl 
Javascript :: random choice js array 
Javascript :: populate dropdown with a variable 
Javascript :: npx: Create react chrome extension 
Javascript :: vue htmlWebpackPlugin.options.title 
Javascript :: discord.js leave guild 
Javascript :: find quotient in javascript 
Javascript :: uuid v4 
Javascript :: references another schema in sequelize 
Javascript :: nodejs increase heap size 
Javascript :: random hexadecimal character js 
Javascript :: hnazmul 
Javascript :: regex min length max length 
Javascript :: auto clicker for cookie clicker 2 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =