In my web page, I would like to play sound when the current time equals to , for example, 5:00 pm.
What I did is:
<script type='text/css'>
var d = new Date();
var m = d.getMinutes();
var h = d.getHours();
if (h == 17 && m == 00){
document.write = "<embed src =\'notify.mp3\' hidden=\'true\' autostart=\'true\' loop=\'true\'></embed>";
}
</script>
I looked for a specific function that plays the sound and I found document.write
which doesn't work and doesn't make sense.
Any suggestion what I should do
Try something like this.
Using The Element
The tag defines a container for external (non-HTML) content. The following code fragment should play an MP3 file embedded in a web page:
Example
Or try
Try using this revised version of the function play()
Refence: http://www.w3schools.com/html/html_sounds.asp
http://webdesign.about.com/od/sound/a/play_sound_oncl.htm
Playing sound with JavaScript
Try this in JS:
Dont forget to add this in HTML
I am assuming you are trying to create an alarm-like functionality. Here's what I would do: