本例子是待办事项的声音提示后刷新页面
先获取到子页面的待办数量,然后ajax轮训请求后台数据,对比差值
注意要写到index页面
<iframe src="{$gourl}" style="width:100%;height: 100%;" frameborder="0" id="appiframe-0" class="appiframe"></iframe>
<audio src="/upload/tishiyin1.mp3" id="supervision-audio" controls="controls" loop="false" hidden="true"></audio>
<script type="text/javascript">
window.onload = function() {
$(function () {
var total = document.getElementById("appiframe-0").contentWindow.document.getElementById('supervision-total');
var user = document.getElementById("appiframe-0").contentWindow.document.getElementById('supervision-user');
if (total != null && user != null && user.value == "qy") {
setInterval(function () {
runEvery10Sec();
}, 10000);
}
function runEvery10Sec() {
if (document.getElementById("appiframe-184admin")) {
totalvalue = document.getElementById("appiframe-184admin").contentWindow.document.getElementById('supervision-total').value;
} else {
totalvalue = document.getElementById("appiframe-0").contentWindow.document.getElementById('supervision-total').value;
}
console.log("轮询待办事件中,当前待办:"+totalvalue);
$.ajax({
type: "POST",
url: "{:Url('supervision/needDealtCount')}",
dataType: "json",
data: {type:"api"},
success: function (ret) {
if (Number(ret) > Number(totalvalue)) {
document.getElementById('supervision-audio').play();
setTimeout( autoRefreshPage, 1000 * 3 );
}
}
});
}
function autoRefreshPage() {
window.location.reload();
}
});
}
</script>