Steve Worswick
Steve Worswick

Reputation: 905

How to make an alert window also play a sound

I can easily make an alert on a website using:

alert("Hello. I am a an alert window");

But how do I also make it beep or play a sound when it displays? I know it's usually bad practice but the person I'm designing for has bad eyesight and needs an audio cue. The person is using Chrome on a laptop. It would be even better if anyone knew of a setting in Chrome that could do this for me.

Upvotes: 1

Views: 642

Answers (1)

Felix Dolderer
Felix Dolderer

Reputation: 471

The answers here probably help you: Playing a sound in a browser (Chrome), from javascript

Besides that, I would create a function like this and call it instead of the native alert function:

function customAlert(message) {
    alert(message);
    playAlertSound(); // Implemented by you somewhere else.
}

Also I am pretty sure the user needs to interact with the website, before the browser allows you to play sound. (Clicking on anything counts as interaction.)

Upvotes: 1

Related Questions