Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Monday, June 17, 2013

JavaScript or Jquery hacks....!

1- If you want to redirect to some other url after some seconds; say 5 seconds here; than you need to do below.

 \$(window).load(function() { window.setTimeout(function() { window.location.href = "https://www.google.co.in"; },5000) });

Here function call at setTimeout is necessary because without it redaction will occure immediately.

NOTE-  Jquery load function is triggered when after loading the page in web-browser. Where as ready() function invoked when DOM is ready.

Below codes  won't work as expected.

document.ready(window.setTimeout(location.href = "https://www.google.co.in",5000));

OR

$(window).load(function() { window.setTimeout(window.location.href = "https://www.google.co.in",5000); });