79293863

Date: 2024-12-19 10:15:34
Score: 1
Natty:
Report link

async function redirect() {

const url = 'https://stackoverflow.com/questions';
const fallbackUrl = 'https://stackoverflow.com/anotherpage';
try {
    const response = await fetch(url); 
    const isUrlValid = response.url.includes('/questions'); // Validate based on part of the URL or criteria
    const redirectUrl = isUrlValid ? url : fallbackUrl;
    document.location.href = redirectUrl; 
  } catch (error) {
    console.error('Error validating URL:', error.message);
    document.location.href = fallbackUrl; 
  }
}

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Imad Eddine Nouali