Posted on April 12th, 2007
7968 views This tutorial is intended for Intermediate JavaScript users, basic knowledge of variables required.
This is the first of five JavaScript redirection tutorials I will be writing.The files used in this tutorial are available for download. (.zip) Table of Contents 1 - Introduction 2 - The Variables and Function 3 - The Page & Conclusion - Introduction After reading and completing this tutorial you will have learned how to make your Browser redirect to a different page after a set amount of time, using variables and functions. We will also make a basic HTML page for our redirection. Lets get started. - The Variables and Function The first thing we are going to do is make our Variables. Variables are commands that tell something what to do when they are called upon; we will be using two of them to set the amount of time we will wait before redirecting, and to set the location of our redirection. Lets make our variables, we will title them redirTime for the time limit, and redirURL for the location. redirTime = "3000"; redirTime tells the site how long to wait before redirecting, redirURL tells the site the location you want to redirect to in this case replace http://www.yoursite.com with your site address. Now for our function it will be called redirTimer function redirTimer() { Our Function redirTimer tells the browser the location of our redirURL variable and the time of our redirTime variable, and then redirects after the time has passed. The final code for our variables and functions. redirTime = "3000"; //Sets the time for our timer - The Page Now that we have our Variables and Functions lets include them into a simple HTML page. The HTML page <html> You can also include the JavaScript from an external file by using <script type="text/javascript" src="myjavascript.js" /> Both ways are included in the tutorial files download. - Conclusion You now know how to redirect a browser after a set amount of time, you also became more familiar with Functions and Variables and how they work. The files used in this tutorial our available for download. (.zip) |