Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda