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

160
Vistas
JS a function that is executed only once
var template = document.querySelector('#template');
var popup = document.querySelector('.popup-bg');
 
template.addEventListener('mouseleave', function(){
  popup.style.display = "block";
}, { once: true });

Hello. A function that displays a popup when the mouse cursor exits the element. It is supposed to work on every subpage, but it is supposed to work only once. The problem is that when you enter another subpage, it will reload and work again.

It is enough for the function to work only once, regardless of the change of the subpage in one session. It may work again (once) when it is visited or refreshed again.

I need an idea how to add a function that will work once and will not reload, or put an element / template on the entire window, which will not reload after changing subpages and refer to it in the function.

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

0

You can save the flag in session storage to achieve the result you want like in this example


var template = document.querySelector('#template');
var popup = document.querySelector('.popup-bg');

if (!sessionStorage.getItem('popup')) {
  sessionStorage.setItem('popup', 'set');

  template.addEventListener('mouseleave', function(){
    popup.style.display = "block";
  }, { once: true });
}
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