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

191
Vistas
The button onclick in html has stopped working

I was making a website that using prompt popup to login. When I click the button, it didn't work. How to slove this problem?

Code here:


<style>
button {
  background-color: #04AA6D;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  cursor: pointer;
  width: 100%;
}
</style>
<script>
function myFunction() {
  let person = prompt("Please enter your username:", "");
  if (person == null || person == "") {
    text = "User cancelled the prompt.";
  } else if (person == "hi" || person == "test" || person == "1234") {
    window.location.href = "youtube.com/c/呂殿下";
  } else {
    window.location.href = "youtube.com";
}
</script>
<button onclick="myFunction();">Click me</button>
</body></html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your function had a couple of errors:

  • single = in first else if
  • no closing } for the else block

In order to make the branching visible, I am logging out the location instead of setting window.location.href for this example.

var text;

function myFunction() {
  let person = prompt("Please enter your username:", "");
  if (person == null || person == "") {
    text = "User cancelled the prompt.";
  } else if (person == "hi" || person == "test" || person == "1234") {
    console.log("setting href to sites.google.com/");
    //window.location.href = "sites.google.com/";
  } else {
    console.log("setting href to google.com");
    //window.location.href = "google.com";
    }
}
button {
  background-color: #04AA6D;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  cursor: pointer;
  width: 100%;
}
<button onclick="myFunction()">Click me</button>

about 4 years ago · Juan Pablo Isaza 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