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

103
Visualizações
Re render element when cookies policy changed with JQuery

The page displayed a video in <iframe>. When cookies are allowed then <iframe> has a [src] attribute <iframe src="http://video....">, when are disabled then has a [data-cookieblock-src] attribute <iframe data-cookieblock-src="http://video....">. When cookies are disabled then the page doesn't display a video, instead display an image banner. The page display an image in a div with a class="hero-banner" and an iframe in a div with a class="youtube-banner". I check which attribute has an iframe and depending on it I toggle a display value block or none. It works as I want but there is one issue. When I visit the page the first time and I allow the page to use cookies, a video should be displayed, and it is only if I refresh the page. I can see that hero-banner and youtube-banner got a display styles. My question is how could I fix this issue?

      $("iframe").each(function() {
        var regexVimeo = /(?:http:|https:|)\/\/(?:player.|www.)?vimeo\.com\/(?:video\/|embed\/|watch\?\S*v=|v\/)?(\d*)/;
        // when cookies are blocked then iframe has attribute data-cookieblock-src in the other way has src
        var iframeDataCookieBlockSrc = $(this).attr('data-cookieblock-src');
        var iframeSrc = $(this).attr('src');

        if(iframeDataCookieBlockSrc) {
          if (iframeDataCookieBlockSrc.match(regexVimeo)) {
            $(".hero-banner").css("display", "block");
            $(".youtube-banner").css("display", "none");
          }
        }

        if(iframeSrc) {
          if (iframeSrc.match(regexVimeo)) {
            $(".hero-banner").css("display", "none");
            $(".youtube-banner").css("display", "block");
          }
        }
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