setTimeout() Function: The setTimeout() method executes a function, after waiting a specified number of milliseconds.
The first parameter is a command/function to be executed and the second parameter indicates the delay time in milliseconds before execution.
This would log “Geeks” to the console, then after three seconds “forGeeks” and in many cases, we are required to some task then wait for some time and proceed another task, so in those cases, we can use the setTimeout method.
Redirecting to multiple websites with some delay: Given the link to various websites, the task is to redirect to them with some delay time. Let the website URL’s be
We have to redirect to all of them one after the other after a delay of 5 seconds. The above problem can be solved by using the below-given code:
When we run the above-given HTML code and click the Redirect Button the site automatically redirects to the above-defined Multiple Websites after a delay time of 5 seconds. This delay time and website to which the site redirects can be changed by changing the values in the script tag of HTML file. In the script tag, we are creating “a”(anchor) tag for every website link which is clicked due to which the website is redirected and the anchor tag is deleted after redirection and another tag is formed after a delay of 5 seconds till we redirect to all the multiple websites links given.