Skip to content
Related Articles

Related Articles

How to Redirect to Another Page After 5 Seconds using jQuery ?

Improve Article
Save Article
  • Last Updated : 14 Jul, 2021
Improve Article
Save Article

In this article, we will learn, how to redirect to another page or URL after a specified time in jQuery. The built-in function used for performing the action is as follows. The setTimeout(callback, delay) function takes two parameters a callback and a time in milliseconds. When this method is called, the callback function will be executed after the specified time. With this method, the callback function is executed only one time after the specified time.

Our goal is to redirect to another page after 5 seconds and this will happen only one time. We use jQuery setTimeout() function



<!DOCTYPE html>
<html lang="en">
    <!-- using jquery library -->
    <h1 style="color: green;">
    <!-- Creating a button -->
    <div class="redirect">
        <button>Redirect me to GFG</button>
    <!-- Script which will redirect 
         us to another page    -->
        // click event on button
            // storing url and time
            let delay = 5000;
            let url = "";
                location = url;

Output: After 5 seconds, the “geeksforgeeks” home page will open.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!