Cover Image for jQuery Redirect to Another Page After 5 Seconds
106 views

jQuery Redirect to Another Page After 5 Seconds

To redirect to another page after 5 seconds using jQuery, you can use the setTimeout function. Here’s a simple example to achieve this:

HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Redirect to Another Page</title>
</head>
<body>
    <h1>Welcome to My Website!</h1>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="script.js"></script>
</body>
</html>

JavaScript (script.js):

$(document).ready(function() {
    // Redirect to another page after 5 seconds
    setTimeout(function() {
        window.location.href = 'https://example.com'; // Replace with the desired URL
    }, 5000); // 5000 milliseconds (5 seconds)
});

In this example, the JavaScript code uses setTimeout to wait for 5 seconds (5000 milliseconds) before redirecting to the specified URL. When the page loads, the function inside setTimeout is executed after the specified time, redirecting the user to the desired page.

Replace 'https://example.com' with the URL of the page you want to redirect to.

With this implementation, the page will automatically redirect to the specified URL after 5 seconds of being loaded.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS