Can I make the browser follow a link after a certain amount of time with jQuery?
I want make a hyperlink turn active and go to that page after a 开发者_开发问答certain amount of time or on pageload. Is this possible with jQuery?
Try this:
setTimeout(followLink, 10000); // 10 seconds
function followLink() {
window.location = jQuery('#myLink').attr('href');
}
jQuery(function() {
followLink();
});
I'll also just note that there's nothing particular to jQuery about this: you could pretty easily do the same thing with plain vanilla JS.
I like this way of doing it:
On document ready:
$(function(){
window.location = $('#link').attr('href');
});
2 seconds after document ready:
$(function(){
setTimeout(function(){
window.location = $('#link').attr('href');
},2000);
});
This jQuery script should do the job:
$('a').click(function(e){
e.preventDefault();
var link = $(this);
setTimeout(function(){
window.location = link.attr('href');
},3000);
});
精彩评论