0

下面的代码是我网站广告的计时器。现在它的设置方式是在启动计时器之前等待页面完全加载。我想做的是稍微改变一下,只等待 5 秒,如果页面还没有完成加载,那么继续并启动计时器。我根本不知道该怎么做。

$(document).ready(function () {
    ptcevolution_surfer();
});

function showadbar(error) {
    $("#pgl").removeAttr("onload");
    if (error == '') {
        $(".adwait").fadeOut(1000, function () {
            $("#surfbar").html('<div class="progressbar" id="progress"><div id="progressbar"></div></div>');
            $("#progressbar").link2progress(secs, function () {
                endprogress('');
            });
        });
    } else {
        $(".adwait").fadeOut(1000, function () {
            $("#surfbar").html("<div class='errorbox'>" + error + "</div>");
            $(".errorbox").fadeIn(1000);
        });
    }
}
/*   End Surf Bar */

function endprogress(masterkey) {
    if (masterkey == '') {
        $("#surfbar").fadeOut('slow', function () {
            $("#vnumbers").fadeIn('slow');
        });
        return false;
    } else {
        $("#vnumbers").fadeOut('slow', function () {
            $(this).remove();
            $("#surfbar").fadeIn('slow');
        });

    }
    $("#surfbar").html("Please wait...");
    var dataString = 'action=validate&t=' + adtk + '&masterkey=' + masterkey;
    $.ajax({
        type: "POST",
        url: "index.php?view=surfer&",
        data: dataString,
        success: function (msg) {
            if (msg == 'ok') {
                $("#surfbar").html("<div class='successbox'>" + adcredited + "</div>");
                $(".successbox").fadeIn('slow');
                if (adtk == 'YWRtaW5hZHZlcnRpc2VtZW50') {
                    window.opener.hideAdminAdvertisement();
                } else {
                    window.opener.hideAdvertisement(adtk);
                }
                return false;
            } else {

                $("#surfbar").html("<div class='errorbox'>" + msg + "</div>");
                $(".errorbox").fadeIn('slow');
            }
        }
    });
}

function ptcevolution_surfer() {
    if (top != self) {
        try {
            top.location = self.location;
        } catch (err) {
            self.location = '/FrameDenied.aspx';
        }
    }
    $("#surfbar").html("<div class='adwait'>" + adwait + "</div>");
}
4

1 回答 1

0

通过您的使用$,我将假设 jQuery

var __init = (function () {
        var initialised = 0; // set a flag, I've hidden this inside scope
        return function () { // initialisation function
            if (initialised) return; // do nothing if initialised
            initialised = 1; // set initialised flag
            ptcevolution_surfer(); // do whatever
        };
    }()); // self-invocation generates the function with scoped var

window.setTimeout(__init, 5e3); // 5 seconds
$(__init); // on page ready

现在会发生什么?该函数第一次被触发时,它会阻止自己被第二次触发,然后开始你想做的任何事情。

于 2013-04-27T07:21:20.310 回答