×
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
41596    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.
Sri Sri Ramakrishna Paramahamsa
If you want to go east, don't go west.
Sri Sri Ramakrishna Paramahamsa
1853
78.07
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     53560
25/06/2018     44607
01/01/2018     43299
28/06/2017     40951
02/08/2017     39903
01/08/2017     33976
06/07/2017     33799
15/05/2017     33063
11/09/2018     29590
14/07/2017     29422
softetechnologies