How to Play audio after page load in JavaScript-Codespeedy

Play audio after page load in JavaScript

Using the Javascript play the audio file after loding page, following the below steps for complete the code.

    Steps:

    HTML
    1. Make sure you have an audio file accessible on your server.
    2. Using Visual studio Code to execute the code.
    3. Using Extendable javscript file.

    JavaScript
    1. Use the audio variable for prompt your audio source file.
    2. Using the window.onload event is used for audio played after the page fully loaded.
    3. Once the page is load the Javascript code is select the audio file by using id.
    4. And then call the play() method for play the audio file.
    5. If any error occur on playing audio it will print “Error playing audio”.

HTML Code:

html file

JavaScript Code:
Js file

–Codespeedy–

Thanks for viewing my page

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top