How do I ping a website to see if its valid before entering?

41 Views Asked by At

So I am just making a basic html page to find a random subsite(?) in the roblox domain. When trying to fetch the site, it shows a redirect error even though loading it manually doesn't. So now I want to try to open the site with inserted code or something automatically then close it if it actually is a running subsite(?)

this is the js code I currently have (everything)

const connect = document.getElementById("connection");
var idsel = document.getElementById("gameid");


function findRandom()
{
    let sel = Math.round(Math.random()*99999999);
    let url = "https://www.roblox.com/games/"+sel+"/";
    connect.setAttribute("href",url);
    idsel.textContent = "Game: "+url;
    

}   

but sometimes it loads in https://www.roblox.com/request-error?code=404 because the game doesnt exist. So instead of reloading every time until it's an actual working game, I want it to try, check the url after loading or ping it before hand, repeat until its a working url. I also want to remove specific games by checking the url or ping it.

0

There are 0 best solutions below