×
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
37324    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
Education is not the learning of facts, but the training of the mind to think.
Albert Einstein
2211
64.28
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     47381
25/06/2018     39476
01/01/2018     39090
28/06/2017     36981
02/08/2017     35706
01/08/2017     29942
06/07/2017     29727
15/05/2017     29213
14/07/2017     25096
11/09/2018     24242
softetechnologies