Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

363
Visualizações
Is there a way to show something when you hover Chrome tabs in Javascript?

I am trying to show an Ad when user scrolls less than 57% but tries to close/switch the browser tab. This is all my JS till now. And also, is there a way to have 1 iteration of the given modal, and only to show it on page refresh. I tried with window.onbeforeunload but it doesn't seem to be working.

// Modal

window.addEventListener("scroll", (e) => {
  let rootElement = document.documentElement;
  let scrollTop = rootElement.scrollTop;
  let pageHeight = rootElement.scrollHeight;
  let getPercent = (scrollTop / (pageHeight - rootElement.clientHeight)) * 100;
  if (getPercent >= 57) {
    document.querySelector(".modal").style.display = "block";
  }

  console.log(getPercent);

  window.onclick = function (e) {
    if (e.target == document.querySelector(".modal")) {
      document.querySelector(".modal").style.display = "none";
    }
  };
});
document.getElementById("close").addEventListener("click", (e) => {
  e.preventDefault();
  document.querySelector(".modal").style.display = "none";
});

function showAd() {
  return (document.querySelector(".modal").style.display = "block");
}

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda