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

132
Visualizações
Recuperar la altura del iframe con Ajax Call

He encontrado muchas preguntas aquí sobre cómo obtener la altura de iframe y configurarla a través de Javascript o jQuery, sin embargo, en mi caso, ninguna funcionó. Instalé el complemento MailChimp en un sitio web de wordpress para cargar los boletines dentro de las pestañas según los años y los meses.

Estoy usando ajax para llamar y devolver el valor de iframe, por lo que el iframe es dinámico y el contenido también. Así que probé todas las formas posibles de cargar la altura correcta y precisa del enlace analizado, sin embargo, no está obteniendo el resultado exacto.

A continuación se muestra mi código:

 jQuery(function() { jQuery('label.tab-label').click(function() { // this.id retrieves the id attribute/property value // of the 'this' element (here the clicked <a> element: var id = jQuery(this).data("id"); var input = jQuery('input[name="tab"]'); input.attr('id', 'tab' + id); // Reset iFrame Load // if (jQuery('.wp-embedded-content').size()){ // jQuery('iframe').remove(); // } var wpajax_url = document.location.protocol + '//' + document.location.host + '/wp-admin/admin-ajax.php?action=get_content'; jQuery.ajax({ cache: false, timeout: 0, url: wpajax_url, data: {post_id: id}, dataType: "json", type: 'POST', success: function(data) { jQuery("div.tab-content").html( data ); jQuery('iframe').attr('allowfullscreen', 'allowfullscreen'); jQuery("div.tab-content").find("iframe").removeAttr("height"); jQuery('iframe').attr('id','newsletter-frame'); function getHeight() { var body = document.body; var html = document.documentElement; var bodyH = Math.max( body.clientHeight, body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); return bodyH; } var height = jQuery('iframe').innerText = getHeight(); console.log('Height is', height); jQuery("div.tab-content").find("iframe").attr("height", height); }, error: function(data) { jQuery("#tab-content").html( 'something went wrong' ); } }); return false; }); });

¿Alguien experimentó eso antes y tiene la solución correcta para devolver dinámicamente la altura del iframe con un 100% de precisión?

Tenga en cuenta que ni CSS ha resuelto el problema ni el atributo de altura.

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