Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

514
Vistas
How to set iframe height dynamically in angular 9?

I am trying to achieve this by 'ngAfterViewInit' and '@ViewChild('iframeContainer') iframeContainer: ElementRef;'

<iframe #iframeContainer [src]="iframeUrl" id="kfsFrame" width="100%" frameBorder="0"></iframe>

.TS FILE CODE :


  ngAfterViewInit(): void {
    this.injectIframe();
  }

 private injectIframe(): void {
    const iframe = this.iframeContainer.nativeElement;

    const height:any = Math.max( iframe.scrollHeight, iframe.offsetHeight, 

      iframe.clientHeight, iframe.scrollHeight, iframe.offsetHeight );

    iframe.setAttribute('width', '100%');

   console.log(height);

    iframe.setAttribute('height', height);

    iframe.setAttribute('frameBorder', '0');

    iframe.addEventListener('load', this.iframeOnLoadtwo);
 }

  public iframeOnLoadtwo(): void {
    console.log('iframe loaded...');
  }```
_______________________________________________

While consoling height [console.log(height);] in console log, it is taking default height which is very less than iframe content height. Currently iframe having scroller bar which I don't want and want height to fit the content.
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda