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

250
Views
Cómo detectar si la conexión a Internet está en línea nuevamente y alertar algo

Estoy usando navigator.online para verificar si Internet está fuera de línea o en línea (sé que es un inconveniente, pero aún es relevante para mi proyecto), ¿cómo puedo alertar un mensaje "Internet ha vuelto" y realizar algunas acciones tan pronto como vuelva Internet?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar el evento en línea o fuera de línea. Recurso

 window.addEventListener("online", () => {}); window.addEventListener("offline", () => {});
about 4 years ago · Juan Pablo Isaza Report

0

Puede consultar esta solución, convertida a JS (enlace de publicación original: https://stackoverflow.com/a/70737477/6696948 )

 window.isDisconnected = false; function setIsDisconnected(val) { window.isDisconnected = val; document.body.textContent = !window.isDisconnected ? "online" : "offline" } function init() { handleConnectionChange(); window.addEventListener("online", handleConnectionChange); window.addEventListener("offline", handleConnectionChange); function handleConnectionChange() { const condition = navigator.onLine ? "online" : "offline"; if (condition === "online") { const webPing = setInterval(() => { fetch("https://jsonplaceholder.typicode.com/todos/1", { mode: "no-cors" }) .then(() => { setIsDisconnected(false); clearInterval(webPing); }) .catch(() => setIsDisconnected(true)); }, 2000); return; } setIsDisconnected(true); } }; init()

about 4 years ago · Juan Pablo Isaza 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!