Sunday 14 September 2014

Redirecting web page onload or delay redirecting

When somebody clicks on link on page to reach specific page, but purposefully developer direct him to another page is called as redirection. Reason behind this may differ for each website.

It can be done in javascript by window.location like this

<script>
window.location="yourlink.com";
</script>

Now it is totally your decision that when you wants to redirect user to that page. If you add above code into the  <head></head>. Then it will perform before your page loaded.

But what if you want it to perform after some delay. You have to do slight addition in this code


<script>
setTimeout(function(){
window.location="yourlink.com";
}, 3000);
</script>

We are using setTimeout for delaying this redirection for 3000 milliseconds i.e 3seconds.
If you want it to be done after page load then try this out

<script>
$(document).ready( function() {
window.location="yourlink.com";
});
</script>


No comments:

Post a Comment