×
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
34945    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.
Swami Vivekananda
If the poor cannot come to education, education must reach them, at the plough, in the bakery factor
Swami Vivekananda
2253
59.21
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     44271
01/01/2018     36693
25/06/2018     36199
28/06/2017     34734
02/08/2017     33282
01/08/2017     27699
06/07/2017     27445
15/05/2017     27055
14/07/2017     22750
11/09/2018     21387
softetechnologies