Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JavaScript Redirect to Another Page After 5 seconds or Some Time Delay in Asp.net

Oct 14, 2012
Introduction

Here I will explain how to redirect to another page after 5 seconds or some time delay in
JavaScript.

Description:
  
In previous articles I explained
JQuery display Current Time on WebPage, JavaScript display current time on asp.net webpage, Disable right click on image and many articles relating to JQuery and JavaScript. Now I will explain how to redirect to another page after 5 seconds or some time delay in JavaScript.

To implement this functionality we need to write the following code


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>JavaScript redirect to another page after 5 seconds or Sometime</title>
<script type="text/javascript">
var i = 0;
function ShowCurrentTime() {
var dt = new Date();
document.getElementById("lblTime").innerHTML = 5 - i + " Seconds";
i++;
if (i == 5) {
setTimeout("location.href='http://www.aspdotnet-suresh.com'", 0);
}
window.setTimeout("ShowCurrentTime()", 1000); // Here 1000(milliseconds) means 1 sec
}
</script>
</head>
<body onload="ShowCurrentTime()">
<form id="form1" runat="server">
<h3>Redirect to Another page Example</h3>
<div>
This Page will Redirect to Another Page within:
<label id="lblTime" style=" font-weight:bold; font-size:x-large"></label>
</div>
</form>
</body>
</html>

Live Demo


Click Button to Redirect:




If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

11 comments :

Aswini said...

Hi

Thank you for this code and i have a doubt about this code in location will we use localhost means it getting an error

Suresh Dasari said...

@Aswini...
Please check the url whatever you given it will work anywhere

Anonymous said...

Thank You very Much sir. This site is very helpful for student like me.


Thanks a lots

Anonymous said...

hello sir, it is not getting redirect....please help me

Anonymous said...

sir what is the use of first script is this essential to write it.....

Suresh Dasari said...

that script file not necessary i updated the post u can check it. This one working fine if you want to check it click on the button in demo section. I hope u did mistake in your code. check it

Anonymous said...

thank u so much for ur quick response u are doing gud job......ankit

Anonymous said...


function Delayer()
{
setTimeout('Redirection()', 10000);
}
function Redirection()
{
window.location="http://www.google.com";
}

this is my code...will u please check this sir is this correct....ankit ankitsaxena22@rediffmail.com

Anonymous said...

actually running time was not showing in label when i was trying ur code....thats y i edited that code.....ankit

Unknown said...

How to use this technics in master page

Anonymous said...

There is no button mentioned in your code but I could see button in your demo page. Can you explain that process?

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.