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

203
Vistas
Run location.replace when the “control” key is clicked
  document.addEventListener('keydown', (event) => {
    var name = event.key;
    var code = event.code;
    if (name === 'Control') {
   location.replace(classroom.google.com)
    }
    if (event.ctrlKey) {
      alert(`Combination of ctrlKey + ${name} \n Key code Value: ${code}`);
    } else {
      alert(`Key pressed ${name} \n Key code Value: ${code}`);
    }
  }, false);
  // Add event listener on keyup
  document.addEventListener('keyup', (event) => {
    var name = event.key;
    if (name === 'Control') {
       location.replace(classroom.google.com)
    }
  }, false);

How currently when I press the control key, nothing happens. If I make it run an alert instead, then the alert will successfully run. Do I need to use the window.location function instead?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The issue with your code is that you aren't passing a string to location.replace().


Right now, your code looks like this.

location.replace(classroom.google.com);

The issue with this code is that you are not surrounding it with quotes to make it a string, so JavaScript thinks that you are referencing a property of an object, of an object.

Below is what JavaScript thinks is happening.

const classroom = {
  google: {
    com: undefined,
  }
};

console.log(classroom.google.com); // undefined


To fix it, simply surround your parameter in quotes, as so.

location.replace("classroom.google.com");

This should successfully redirect you to classroom.google.com!

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