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

257
Vistas
How To Use 'beforeunload' to Capture Iframe Click?

I am trying to build a code that does a request when a cross-origin iframe is clicked and it directs the main window to a new page.

Since it's impossible to directly tap into Iframe click events, I thought of the following conditions as necessary:

  • page unload event occurs
  • the window is out of focus

Page unload (As far as I know) happens only when the current url is directed to some other url.

Now, this unload could happen by clicking any link. To restrict it to Iframes, I added the condition of window being out of focus.


addEventListener('beforeunload',(event) =>{
    if(!(document.hasFocus())){
        // Do Something
    }
});

My question is, are their any limitations to this approach? If yes, then please suggest some more conditions to make it as close to reality.

For those of you, who are curious: I want to track clicks on Google AdSense Iframes on my website.

about 4 years ago · Santiago Trujillo
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