What's new

Help Random next page in html (for bot only)

V_1 M

Forum Guru
Elite
create an html with javascript that will redirect the user to a random website from a list of websites
 
Sure! Below is an example of an HTML page with JavaScript that will redirect the user to a random website from a list of websites when the page is loaded:

HTML:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Random Website Redirect</title>
</head>

<body>
    <script>
        // List of websites to choose from
        const websites = [
            "https://www.example.com",
            "https://www.example.org",
            "https://www.example.net"
        ];

        // Get a random index from the list
        const randomIndex = Math.floor(Math.random() * websites.length);

        // Redirect the user to the random website
        window.location.href = websites[randomIndex];
    </script>
</body>

</html>

You can add more websites to the websites array to include additional options for redirection. When the page is loaded, the JavaScript code will select a random website from the list and redirect the user to that website.
 
You can add more websites to the websites array to include additional options for redirection. When the page is loaded, the JavaScript code will select a random website from the list and redirect the user to that website.
add it inside when button got clicked
 
add it inside when button got clicked
Certainly! If you want the redirection to happen when a button is clicked, you can modify the code to include an event listener on a button click. Here's an example:

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Random Website Redirect</title>
</head>
<body>
    <button id="redirectButton">Click to Visit a Random Website</button>

    <script>
        // List of websites to choose from
        const websites = [
            "https://www.example.com",
            "https://www.example.org",
            "https://www.example.net"
        ];

        // Function to redirect to a random website
        const redirectToRandomWebsite = () => {
            const randomIndex = Math.floor(Math.random() * websites.length);
            window.location.href = websites[randomIndex];
        };

        // Event listener for button click
        document.getElementById("redirectButton").addEventListener("click", redirectToRandomWebsite);
    </script>
</body>
</html>

In this code snippet, a button with the id "redirectButton" is created. When the button is clicked, the redirectToRandomWebsite function is called, which selects a random website from the list and redirects the user to that website.
 
prevent reappearing of website twice or more
To prevent the same website from appearing more than once in the random selection process, you can keep track of the websites that have already been visited and remove them from the list before selecting the next random website. Here's an updated code snippet that ensures the same website is not visited twice or more:

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Random Website Redirect</title>
</head>
<body>
    <button id="redirectButton">Click to Visit a Random Website</button>

    <script>
        // List of websites to choose from
        const websites = [
            "https://www.example.com",
            "https://www.example.org",
            "https://www.example.net"
        ];

        // Array to store visited websites
        let visitedWebsites = [];

        // Function to redirect to a random website
        const redirectToRandomWebsite = () => {
            // Remove visited websites from the list
            const availableWebsites = websites.filter(website => !visitedWebsites.includes(website));

            if (availableWebsites.length === 0) {
                alert("You have visited all websites!");
                return;
            }

            const randomIndex = Math.floor(Math.random() * availableWebsites.length);
            const selectedWebsite = availableWebsites[randomIndex];
            
            // Add the selected website to visited websites
            visitedWebsites.push(selectedWebsite);
            
            // Redirect to the selected website
            window.location.href = selectedWebsite;
        };

        // Event listener for button click
        document.getElementById("redirectButton").addEventListener("click", redirectToRandomWebsite);
    </script>
</body>
</html>

In this code, the visitedWebsites array keeps track of the websites that have already been visited. Before selecting a random website, the code filters the websites array to exclude the visited websites. If all websites have been visited, an alert is shown. Otherwise, a random website from the available websites is selected for redirection, and the selected website is added to the visitedWebsites array to prevent it from being visited again.
 

Similar threads

Users search this thread by keywords

  1. website create
Back
Top