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

76
Visualizações
Change page title after specific time when user on other tab with other website

I am trying to change the title of my page after 1 minute, when visitor change the tab and changed tab should contain other website (for eg. www.youtube.com) and title should flashes alternatively after every 2 seconds with 'original title'and 'changed title'.

case 1: when 0 product added to cart, title of page should flashes with 'original title' and 'We miss you title'

case 2: When 1 or more products added into cart. title of page should flashes alternatively 'original title' and '1 product in your cart title'

case 3: When visitor come to original tab flashing of title should stop and it should show original title only.

var cartCount = parseInt($('.cart-count').text()); // gives cart count
var currentDomain = (document.domain); // current domain
var pageTitle = $(document).find("head title").text(); // page title

// checking tab change

document.addEventListener("visibilitychange", function() { 
  setTimeout(changeTitleFirst, 60000); // 1 minute timeout
  function changeTitleFirst(){
    setInterval(changeTitle, 2000);
    function changeTitle(){
      if(document.visibilityState === "hidden" && cartCount === 0){
          if(pageTitle !== "miss you"){
          $(document).find("head title").text("miss you");  
          } else {
          $(document).find("head title").text(pageTitle);
        }
      } 
      else if (document.visibilityState === "hidden" && cartCount > 0){
        if($(document).find("head title").text() !== "come back"){
           $(document).find("head title").text("come back");  
        } else {
          $(document).find("head title").text(pageTitle);
        }
      }
      else if (document.visibilityState !== "hidden"){
        $(document).find("head title").text(pageTitle);
      } else {
        return;
      }
    }   
  }
});

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