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.
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. |
|||
|
|||
11 comments :
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
@Aswini...
Please check the url whatever you given it will work anywhere
Thank You very Much sir. This site is very helpful for student like me.
Thanks a lots
hello sir, it is not getting redirect....please help me
sir what is the use of first script is this essential to write it.....
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
thank u so much for ur quick response u are doing gud job......ankit
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
actually running time was not showing in label when i was trying ur code....thats y i edited that code.....ankit
How to use this technics in master page
There is no button mentioned in your code but I could see button in your demo page. Can you explain that process?
Note: Only a member of this blog may post a comment.