Javascript redirect

Page 1 / 1

If you want to redirect your visitors to another page automatically, you can use a javascript function that will allow you to set a delay before forwarding if you wish. However, note that this is a redirect on client side (because javascript is executed on the client side) and not a server redirection (by PHP for example).
This script should be placed between the <body> and </body> tag of your webpage.
The advantage of using a javascript redirect is the fact it can be triggered after clicking on a button or any other action made ​​by the visitor.

Warning : Javascript must be enabled in the Web browser of the visitor (enabled by default) for this to work.

  1. Automatic redirect after x seconds on page load
  2. Automatic redirect after x seconds on click

1. Automatic redirect after x seconds on page load

In this case, the countdown starts when the page (on which you insert this code) loading.

If you want to redirect the visitor after x seconds from loading of the page. Simply enter this code into your page.
Note : Preferably at the end of the page. Before the </body>.

Code : Javascript

<script type="text/javascript">
// Redirect script created by InformatiWeb.net
var delai=3; // Delay in seconds
var url='/folder/destination_page.php'; // Destination url
setTimeout("document.location.replace(url)", delai + '000');
</script>

2. Automatic redirect after x seconds on click

If you want to trigger this redirection after clicking a button or other, we recommend that you place it first in a function. Then simply, to call this function by the desired event.

Here's the function :

Code : Javascript

<script type="text/javascript">
// Redirect script created by InformatiWeb.net
function redirection_js(url,delai){
  setTimeout("document.location.replace('"+url+"')", delai + '000');
}
</script>

And here's how to use it with the click event (or onclick). You can of course use other events like "onmousedown", "onmouseover", ...

To use this function, simply pass the following parameters :
- url : the address to redirect the visitor
- delai : Delay in seconds before redirecting

Code : Javascript

<input type="submit" name="my_button" id="my_button" value="Button text" onclick="redirection_js('/folder/destination_page.php','3')" />

 

If you don't want to use Javascript, you can create a HTML redirection.