Javascript通知每秒出现一次

时间:2015-10-21 17:20:43

标签: javascript wordpress loops header notifications

页面一次又一次地执行javascript通知(Noty插件)(几乎每秒)。 (平台是:Wordpress) 它仅发布在帖子页post page example上,但主页Homepage link和其他页面除外。 标题中添加的原始Javascript通知代码是

<link rel="stylesheet" type="text/css" href="http://cdn.frkmusic.info/static/buttons.css"/>
<link rel="stylesheet" type="text/css" href="http://cdn.frkmusic.info/static/animate.css"/>
<script src="http://cdn.frkmusic.info/static/jquery-1.7.2.min.js"></script>

<!-- noty -->
<script type="text/javascript" src="http://cdn.frkmusic.info/static/js/noty/packaged/jquery.noty.packaged.min.js"></script>
<script type="text/javascript" src="http://cdn.frkmusic.info/static/notification_html.js"></script>

<script type="text/javascript">


    function generate(type, text) {

        var n = noty({
            text        : text,
            type        : type,
            dismissQueue: true,
            layout      : 'topRight',
            closeWith   : ['click'],
            theme       : 'relax',
            maxVisible  : 10,
            animation   : {
                open  : 'animated bounceInLeft',
                close : 'animated bounceOutRight',
                easing: 'swing',
                speed : 500
            }
        });
        console.log('html: ' + n.options.id);
    }

    function generateAll() {
        generate('alert', notification_html[0]);
    }

    $(document).ready(function () {

        setTimeout(function() {
            generateAll();
        }, 500);

    });

</script>

1 个答案:

答案 0 :(得分:0)

尝试清除超时...未经测试: - /

    var timeout = null;

    function generate(type, text) {

        var n = noty({
            text        : text,
            type        : type,
            dismissQueue: true,
            layout      : 'topRight',
            closeWith   : ['click'],
            theme       : 'relax',
            maxVisible  : 10,
            animation   : {
                open  : 'animated bounceInLeft',
                close : 'animated bounceOutRight',
                easing: 'swing',
                speed : 500
            }
        });
        clearTimeout(timeout);
        console.log('html: ' + n.options.id);
    }

    function generateAll() {
        generate('alert', notification_html[0]);
    }

    $(document).ready(function () {

        timeout = setTimeout(function() {
            generateAll();
        }, 500);

    });