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

178
Vistas
Why the browser has a beforeunload event even though I do not use it in my codes?

I have a function to help the user scroll up to the top of the page like this:

function toTheTop(){
        document.getElementByID('topUpBtn').addEventListener('click', ()=>{
            scrollTo( { top: document.querySelector('h1').getBoundingClientRect().top,
        behavior: 'smooth'})
    });
}

export {
    toTheTop
}

I am using Webpack for code organization. I called toTheTop function in an entry point as below:

import { toTheTop } from './js/TopUpButton.js';

if(document.readyState !== 'loading') {
    console.log('document is already ready');
    toTheTop();
} 
else{
    document.addEventListener('DOMContentLoaded', ()=>{
        console.log('document was not ready'),
        toTheTop();
    });
}

export {
    toTheTop
}

I have tested this function without Webpack and it worked. However, when using with Webpack, it didn't. Inspect the console for the button I only see:

DOMContentloaded
click

But with Webpack setup, I see a weird line named beforeunload in order like this:

beforunload
click

open this line I saw:

self.addEventListener("beforeunload", function () {
  status.isUnloading = true;
});

I did not implement this code at all. I looked for the use of beforeunload - this is only used if we want to prompt something for the user before leaving a page.

My questions are: Why do I have the beforeunload event-handler in my code? Does this relate to my Webpack setup? And how can I solve my problem?

I tried to figure it out for several days, but still can't handle it.

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

0

I have fixed it. Fortunately there is nothing wrong with my code. The function did not work because css elements conflicting with each other on different pages. It was hard to find but thank you guys. Posting a question helps me think it twice.

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