Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

94
Views
Javascript/jQuery antes de descargar y descargar sin disparar

Tengo una página en la que quiero que mi secuencia de comandos le informe al servidor que el usuario se desconectó cuando se cerró el navegador/pestaña/página.

 $(document).ready(function() { // Inform the server that the user went online setStatus('online'); // Inform the server that the user went offline $(window).on('beforeunload', function() { setStatus('offline'); }); // Inform the server that the user went offline $(window).on('unload', function() { setStatus('offline'); }); }); async function setStatus(status) { let { data } = await axios.post('/status', { status: status }); }

La parte donde tengo setStatus('online'); funciona, pero parece que nunca puedo establecer el estado en fuera de offline cuando cierro la página/pestaña/navegador.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Mirando a mi alrededor, encontré esta muy buena respuesta : solo tenía que poner esto en mi archivo server.js :

 peer.oniceconnectionstatechange = function() { if(peer.iceConnectionState == 'disconnected') { console.log('Disconnected'); } }

Toma unos segundos antes de que registre que el compañero se ha caído, pero al menos siempre está disparando y eso es lo suficientemente confiable para mí.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!