Categories
JavaScript Answers

How to play a notification sound on websites with JavaScript?

Spread the love

To play a notification sound on websites with JavaScript, we call the play method.

For instance, we write

const audio = new Audio(url);
audio.play();

to create an audio element with the audio url with the Audio constructor.

Then we call play to play the clip.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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