Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
How to revert to windows if JS value is null

I have like no JS experience, but I need help.

So I have a code that allows a user to manually enter a URL.

Well, If they leave the value blank and click out it "NULLS". I want a way to detect that null and revert back to "/" or the same page instead of /null

function url(){
    swal("Enter a URL:", {
        content: "input",
      })
      .then((value) => {
        location.replace(value);
        
      });
}
// PROD Fix, needs a zero-null failure-fix. Find a way to prevent zero-data/null.

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

You can add a test for the null value before the location.replace() and change the value to the url you want as default.

function url(){
    swal("Enter a URL:", {
        content: "input",
      })
      .then((value) => {
        if (value === null) value = "your replacement url";
        location.replace(value);
        
      });
}
about 4 years ago · Santiago Gelvez Denunciar

0

Careful with the check if (value === null) if you can receive either null or an empty string. The condition will fail, if you receive an empty string.

I would use if (!value) instead to cover both null && "".

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda