How to Play a Sound from a Web Page

This one works for IE7, FF3, Safari, Chrome:

<embed src="/sounds/beep.wav" autostart="false" width="0" height="0" id="alarmsound" enablejavascript="true">
<script type="text/javascript">
//<![CDATA[
function playAlarm()
{
var thissound=document.getElementById("alarmsound");
thissound.Play();
}
setTimeout("playAlarm()",1000);
//]]>
</script>

From Demonstration of Different ways to Play a Sound from a Web Page

Advertisements

2 Responses to “How to Play a Sound from a Web Page”

  1. Rik Hemsley Says:

    Perhaps warn whoever does this that they might annoy visitors?

  2. Dirk Says:

    @Rik: Yes, you are right.

    I have used the code on webpages of our monitoring software PRTG Network Monitor. It only plays when there are alarms (=unreachable servers etc.)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: