×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
audio and video Tag Share Google Drive Audio by HTML
Playing audio after the page loads in html5 - HTML 5
33640    Arnab De    10/01/2019

Playing audio after the page loads in html

In HTML5 we can play a audio file using the <audio> tag. It show a simple audio controller in the web page. when we click on the play button of the controller then the specific audio is playing. But we can playing any audio in html automatically just after loding the page or just after refresh the page. We use an <audio> without any controller. and a very simple code in java script or jQuery to playing the audio.

softetechnologies

HTML Code

<audio id="tah_audio" src="bg.mp3" loop="loop"></audio>

Java Script Code

window.onload = function() {
    document.getElementById("tah_audio").play();
}

or we can use the following jQuery

$(document).ready(function() {
    $("#tah_audio").get(0).play();
});

We can also play audio on page load without using any Javascript or JQuery. Only write the following HTML5 code.

<audio autoplay>
  <source src="tah.mp3" type="audio/mpeg">
</audio>

softetechnologies
audio and video Tag Share Google Drive Audio by HTML
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Albert Einstein
Imagination is everything. It is the preview of life's coming attractions.
Albert Einstein
3549
51.71
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     41742
01/01/2018     35913
28/06/2017     33954
25/06/2018     33200
02/08/2017     32305
06/07/2017     26716
01/08/2017     26706
15/05/2017     26325
14/07/2017     21729
21/04/2018     20622
softetechnologies