简体   繁体   English

页面更改时用声音提醒用户

[英]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). 当我更新服务器上的文件时,html页面会自动更改html页面(每9秒检查一次更改)。

How can I trigger a chime sound file to alert a user of a html page change? 如何触发提示音文件以提醒用户html页面更改?

Here is the html: 这是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: 您可以使用javascript轻松创建HTML音频元素:

<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() 在使用.append()或其他方法在jquery中创建它之后,只需在ms中以您的文件长度添加.delay(2000),然后使用.remove()再次删除该元素

eg 例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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