I have a webpage and whoever gets on that page, I want to redirect them to different location.
So,
IF current link in address bar is www.site.com/mypage?a=paramApple
then redirect to www.google.com
IF current link in address bar is www.site.com/mypage?a=paramMango
then redirect to www.yahoo.com
else
redirect to www.bing.com
So, I am trying to add a counter / timer also so that user will be navigated in 5 seconds and countdown will be displayed on the page so that user know about the redirection.
This is my code, how can I add countdown to this redirection code?
<script>
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
var end =setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
if (--timer < 0) {
window.location = "http://www.mywebsite.com/";
clearInterval(end);
}
}, 1000);
}
window.onload = function () {
var fiveMinutes = 5,
display = document.querySelector('#time');
startTimer(fiveMinutes, display);
};
</script>
<script language="javascript">
window.onload=function(){
var keys = (window.location.search || "").split("=");
var url = "//www.bing.com";
if(keys.length>1){
if(keys[1].indexOf("paramApple")>-1)
url="//www.google.com";
else if(keys[1].indexOf("paramMango")>-1)
url="//www.yahoo.com";
}
window.location=url;
};
</script>
<div><h3>You will be redirected in <span id="time">00:05</span></h3>
<script type="text/javascript">
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
var end = setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
if (--timer < 0) {
var keys = (window.location.search || "").split("=");
// http://localhost:22620/WebForm29.aspx?a=paramMango
var url = "//www.bing.com";
if (keys.length > 1) {
if (keys[1].indexOf("paramApple") > -1)
url = "//www.google.com";
else if (keys[1].indexOf("paramMango") > -1)
url = "//www.yahoo.com";
}
window.location = url;
clearInterval(end);
}
}, 1000);
}
window.onload = function () {
var fiveMinutes = 5,
display = document.querySelector('#time');
startTimer(fiveMinutes, display);
};
</script>
<div>
<h3>You will be redirected in <span id="time">00:05</span></h3>
</div>
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Thank you so much for the update. That's exactly what I was looking for.
One more small request. I would like to keep everything same but just add a button that says "Click to continue" .
The button basically will speed up the process and users who do not want to wait for the countdown will be able to skip the process and continue with the destination page.
"Continue" button will still take the user to the destination location as per the URL parameter.
Member
84 Points
1516 Posts
Redirecting pages based off URL parameter?
Jan 18, 2017 05:14 PM|jeffcarter|LINK
I have a webpage and whoever gets on that page, I want to redirect them to different location.
So,
How to do this?
All-Star
15186 Points
3888 Posts
Re: Redirecting pages based off URL parameter?
Jan 18, 2017 05:38 PM|raju dasa|LINK
Hi,
Try adding this JS code in your webpage:
//code not tested.
rajudasa.blogspot.com || rajudasa-tech
Member
84 Points
1516 Posts
Re: Redirecting pages based off URL parameter?
Jan 18, 2017 06:51 PM|jeffcarter|LINK
Thank you @raju
So, I am trying to add a counter / timer also so that user will be navigated in 5 seconds and countdown will be displayed on the page so that user know about the redirection.
This is my code, how can I add countdown to this redirection code?
All-Star
45489 Points
7008 Posts
Microsoft
Re: Redirecting pages based off URL parameter?
Jan 19, 2017 06:07 AM|Zhi Lv - MSFT|LINK
Hi
You could modify your code as below:
Best regards,
Dillion
Member
84 Points
1516 Posts
Re: Redirecting pages based off URL parameter?
Jan 19, 2017 07:36 PM|jeffcarter|LINK
Hi Dillion,
Thank you so much for the update. That's exactly what I was looking for.
One more small request. I would like to keep everything same but just add a button that says "Click to continue" .
The button basically will speed up the process and users who do not want to wait for the countdown will be able to skip the process and continue with the destination page.
"Continue" button will still take the user to the destination location as per the URL parameter.
Please help with the code?
All-Star
15186 Points
3888 Posts
Re: Redirecting pages based off URL parameter?
Jan 20, 2017 06:24 AM|raju dasa|LINK
Hi,
Try this code:
rajudasa.blogspot.com || rajudasa-tech