如何在重定向之前保持页面5秒钟

时间:2012-02-16 09:38:18

标签: javascript jquery html5

我有一个页面,其中包含指向其他页面的链接。 我希望在重定向到另一个页面之前保持页面5秒钟。

我正在使用jquery和javascript与HTML5和CSS3。

3 个答案:

答案 0 :(得分:4)

您可以将事件处理程序与setTimeout()一起使用,如下所示:

jQuery('a.external').on('click', function(event){
    event.preventDefault();
    var href = jQuery(this).attr('href');
    setTimeout(function(){
        window.location = href;
    }, 5000);
});

这适用于您指定“external”类的每个锚点。

答案 1 :(得分:1)

在javascript中:

setTimeout(function() {
    window.location.assign('http://www.google.com');
}, 5000);

答案 2 :(得分:1)

查看the setTimeout method

setTimeout(function() {
  window.location.assign('http://yourWebsite.com/otherPage');
}), 5000);