JavaScript redirect page
This article helps you to learn how to use Javascript redirect possibilities and show you some code easy code examples.
Tutorial info:
| Name: | JavaScript redirect page |
| Total steps: | 1 |
| Category: | Basics |
| Date: | 2010-08-05 |
| Level: | Beginner |
| Product: | See complete product |
| Viewed: | 6531 |
Bookmark JavaScript redirect page
Step 1 - JavaScript redirect usage
JavaScript redirect page
During reorganization of your website it can happen that you want to redirect your visitor to an other page. You can do this many ways, like PHP, HTML, JavaScript. On this page we focus on the JavaScript solution.
You should know however, that if JavaScript is disabled in your visitors browser, then this way will not work and you need to use an other redirecting method.
The simplest way to redirect the user with JavaScript is setting the window.location property to the URL you want to redirect to as follows:
Code:
<script type="text/javascript">
window.location = "http://www.javascriptf1.com"
</script>
As you can see the code is very simple.
Sometimes you don’t want to redirect the user immediately, but a bit later. For example you want to inform the visitor why and where he or she will be redirected. To solve this problem we need to setup some delay before redirecting using the setTimout() function as you can see in the following code example:
Code:
This page will be redirected in 5 seconds...
<script type="text/javascript">
setTimeout('window.location = "http://www.javascriptf1.com"', 5000);
</script>
I hope this short description helps you to use JavaScript redirect to any page solution properly.
Tags: javascript redirect page, javascript redirect, redirect page, javascript, redirect, page
| JavaScript redirect page - Table of contents |
|---|
| Step 1 - JavaScript redirect usage |