PDA

View Full Version : Timed redirect with option not to redirect?



nite1x
Feb 6th, 2005, 08:51 AM
I recently redesigned a webpage I had built earlier and broke it up into smaller chunks dispaying on separate pages. I want to redirect people to the new page. I found this script for a timed redirect.


<!-- TWO STEPS TO INSTALL TIMED REDIRECT:

1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: [email protected] -->
<!-- Modified: Benjamin Wright, Editor -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
redirTime = "15000";
redirURL = "http://javascript.internet.com/new";
function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); }
// End -->
</script>


<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->

<BODY onLoad="redirTimer()">

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 0.88 KB -->
Is there a way to stop the redirect? For example put a line at the top of the page that says "This page has be redesigned. You will be redirected to the new page in 20 seconds unless you press the button to remain on this page." Then put a button to stop the redirect.

Nite

_Aerospace_Eng_
Feb 6th, 2005, 11:11 AM
yep using the window.clearTimeout function

<!-- TWO STEPS TO INSTALL TIMED REDIRECT:

1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: [email protected] -->
<!-- Modified: Benjamin Wright, Editor -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
redirTime = "10000";
redirURL = "http://javascript.internet.com/new";
function redirTimer() {
settime=self.setTimeout("self.location.href = redirURL;",redirTime);
}
function stopredir(){
window.clearTimeout(settime);
document.getElementById('sometext').innerHTML="The URL redirect will no longer occur";
}
// End -->
</script>


<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->

<BODY onload="redirTimer()">

<p><center>
<font face="arial, helvetica" size="2">
"This page has be redesigned. You will be redirected to the new page in 10 seconds unless you press the button labeled 'stop redir' to remain on this page."<br><br>
Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p><br>
<p style="text-align:center;margin:0px;"><input type="button" value="stop redir" id="stop1" onclick="stopredir()"></p>
<div id="sometext" style="text-align:center;"></div>

<!-- Script Size: 0.88 KB -->

nite1x
Feb 6th, 2005, 09:21 PM
Thanks Aerospace

your code works perfectly :thumbsup:
If you want to see the results users.igl.net/nite1x/yghelp1.html (http://users.igl.net/nite1x/yghelp1.html).

Nite