开发者

Reload when setTimeout function finishes

I want to reload window after a this custom function finishes:

<script type="text/javascript">
$(document).ready(function(){
    setTimeout(function () {
        $('#order_form').dolPopupHide({});
    }, 3000);
    //window.location.reload();
});
</script>

Is there a way I can add the reload to the setTimeout function so it doesn't run until t开发者_如何学Pythonhe timeout is over?


reload needs to be inside your function:

$(document).ready(function(){
    setTimeout(function () {
        $('#order_form').dolPopupHide({});
        window.location.reload();
    }, 3000);

});

If you want to conceptually separate the work from the reload, you can do something like this:

$(document).ready(function(){
    setTimeout(function () {
        doWork();
        window.location.reload();
    }, 3000);

    function doWork() {
        $('#order_form').dolPopupHide({});
    }

});

Or, to be even more general:

function reloadAfterExec(fn) 
    return function() {
        fn();
        window.location.reload();
    }
}

$(document).ready(function(){
    setTimeout( reloadAfterExec(function() {
        $('#order_form').dolPopupHide({});
    }), 3000);

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜