Question

redirect page to another page after few seconds

i have 2 websites, i want to make a new website and include both of my sites in that website and show them in index page and i want to redirect my index page to my other websites after 10-15 seconds only.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
July 18, 2023

Heya,

Based on your question, it sounds like you want to create a new landing page that displays links to your two other websites and then automatically redirects the user to these sites after 10-15 seconds. This can be done by creating a simple HTML page with JavaScript for the automatic redirection.

Here’s an example of how you can set this up:

<!DOCTYPE html>
<html>
<head>
    <title>Your New Site</title>
    <script type="text/javascript">
        var counter = 0;
        var urls = ['http://your-first-website.com', 'http://your-second-website.com'];

        function redirect() {
            setTimeout(function() {
                window.location.href = urls[counter];
                counter = (counter + 1) % urls.length;  // Cycle through the urls
                redirect();  // Set the next redirection
            }, 10000);  // Change the time to the desired delay in milliseconds, 10000 milliseconds = 10 seconds
        }
    </script>
</head>
<body onload="redirect()">
    <h1>Welcome to My New Site</h1>
    <p>Check out my other websites:</p>
    <ul>
        <li><a href="http://your-first-website.com">First Website</a></li>
        <li><a href="http://your-second-website.com">Second Website</a></li>
    </ul>
</body>
</html>

This code creates a new HTML document with links to your two other websites. The JavaScript code sets a timer that redirects to the first URL after the delay specified (10 seconds in this case), and then redirects to the second URL after another delay, and so on.

Note that this is a simple implementation and does not persist the counter between page loads. That means if a user visits your page, they will always be redirected to the first URL after the delay. If you want to alternate between the two URLs for a single user, you will need to store the counter in a more persistent manner, like a cookie or local storage.

Remember to replace 'http://your-first-website.com' and 'http://your-second-website.com' with the actual URLs of your two websites.

Please note that auto-redirecting can create a confusing user experience and is generally not recommended. Consider using this sparingly and informing the user that they will be redirected.

You can redirect it with HTML, PHP or Java-script.

Here are the code for HTML: create index.html and place this code in head HTML

<meta http-equiv="refresh" content="15; URL='URL of website 2'" />

Change content to any value its in seconds

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.