- Published on : 21 May 2013 at 15:29 UTC
- Lionel Eppe
This script should be placed between the <body> and </body> tag of your webpage.
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>.
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 :
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
<input type="submit" name="my_button" id="my_button" value="Button text" onclick="redirection_js('/folder/destination_page.php','3')" />