how to play sound on load js

JavaScript
var sample = document.getElementById("foobar");
sample.play(); <audio id="foobar" src="yoursample.ogg" preload="auto">  #foobar { display: none }
Source

Also in JavaScript: