html5+js 实现iframe嵌套页面的轮训播放提示音

本例子是待办事项的声音提示后刷新页面

先获取到子页面的待办数量,然后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>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值