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

240
Visualizações
I want to add css class dynamically to body when that page has <iframe> and want to remove that class when no <iframe> in other pages

I want to hide scrollbar of parent website and show iframe scrollbar only. But when i apply overflow hidden property to body it will be applied globally but i want to apply only that page where is available. How can i do that? can anyone can help me please?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Use JavaScript to determine the existence of iframe element and then remove or add class to body tag accordingly. Here's how:

if(!document.querySelector('iframe')){
   document.querySelector('body').classList.add = "newClass";
} else{
   document.querySelector('body').classList.remove = "newClass"; //In case class was already added
}

Hope this solves your question.

about 4 years ago · Juan Pablo Isaza Relatório

0

For adding/remove class to body you can write js code like:

If you use jQuery:

jQuery(document).ready(function ($) {
  if ( $('iframe').length ) {
    $(body).addClass('is-iframe');
  } else {
    $(body).removeClass('is-iframe');
  }
});

Pure js:

window.addEventListener("load", function(event) {
  if ( document.querySelector('iframe') ){
    document.querySelector('body').classList.add('is-iframe')
  } else {
    document.querySelector('body').classList.remove('is-iframe')
  }
});

I think you can also set some styles for body.is-iframe and for iframe element:

body.is-iframe {
  position: relative;
  width: 100vw;
  height: 100vh;
}

body.is-iframe iframe {
  position: aboslute;
  width: 100%;
  height: 100%;
  overflow-y: auto;
}

I didn't test this code yet, but I guess it should work.

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