×
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
41168    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
Education is the manifestation of the perfection already in man.
Swami Vivekananda
750
74.12
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     52112
25/06/2018     43898
01/01/2018     42913
28/06/2017     40662
02/08/2017     39479
01/08/2017     33676
06/07/2017     33497
15/05/2017     32772
14/07/2017     29039
11/09/2018     28969
softetechnologies