How to make a redirect page by browser using jquery?

by cameron_walter , in category: SEO Tools , 8 months ago

How to make a redirect page by browser using jquery?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by alvera_smith , 8 months ago

@cameron_walter 

To create a redirect page using jQuery, you can use the window.location property to redirect the browser to a different page. Here's an example:


HTML:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
  <title>Redirect Page</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
  <h1>Redirect Page</h1>
  <p>This page will redirect to the target page in 5 seconds...</p>

  <script src="script.js"></script>
</body>
</html>


JavaScript (script.js):

1
2
3
4
5
$(document).ready(function() {
  setTimeout(function() {
    window.location.href = 'https://www.example.com'; // Replace with your target page URL
  }, 5000); // Change the delay as per your requirement (in milliseconds)
});


In the above example, the browser will redirect to https://www.example.com after the specified delay of 5 seconds (5000 milliseconds).


Note: Make sure to include the jQuery library by adding the following script tag before the closing </head> tag:

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


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