I know that we can delay the url redirection easily with plain javascript below,
setTimeout(function(){ document.location = 'http://stackoverflow.com/';}, 2000 );
what if I want to use jQuery's delay()?
$(window.location).delay(4000).attr('href', 'http://stackoverflow.com/');// fail to work!
Any ideas?
thanks.
Simple answer: don't use .delay() or attempt to, it's a round-about really non-sensical way to get what you're after, since it's just calling setTimeout() underneath.
It wasn't designed for this at all (it's for queuing, and then primarily for animations), and you're trying to use the location in a $() wrapper (which is trying to use it as a selector), which is also wrong.
Use jQuery (or any other abstraction layer, in any language) when it makes sense to do so, it definitely makes no sense here, use setTimeout(), save yourself the confusion and the client the CPU cost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With