简体   繁体   中英

Alert user with sound when page changes

When I update a file on my server the html page automatically changes the html page (checks every 9 seconds for changes).

How can I trigger a chime sound file to alert a user of a html page change?

Here is the html:

<html><head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
 $(document).ready(function() {
      $("#responsecontainer").load("data.txt");
      var refreshId = setInterval(function() {
      $("#responsecontainer").load('data.txt?randval='+ Math.random());
}, 9000);
$.ajaxSetup({ cache: false });
});
</script> 
</head>

<body bgcolor=#befcb4>
<div id="responsecontainer"></div>
</body></html>

If you're problem is triggering the actual sound, you can find that here . As far as determining whether there is a new element in the page, I'd just compare it to the old one.

You can easliy create a HTML Audio Element with javascript:

<audio autoplay><source src="youraudiofile.mp3" type="audio/mp3"></audio>

After you created it in jquery with .append() or whatever just add an .delay(2000) in ms with your length of your file and then remove that element again with .remove()

eg

var audioElement = $('<audio autoplay id="music"><source src="youraudiofile.mp3" type="audio/mp3"></audio>');
$("body").append(audioElement).delay(1000).remove("#music");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM