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

134
Visualizações
Retrieve Iframe Height with Ajax Call

I have found many questions here about getting iframe's height and set it via Javascript or jQuery however in my case none have worked. I've installed MailChimp Plugin on a wordpress website to load the newsletters within tabs based on years and months.

I'm using ajax to call and return the value of iframe thus the iframe is dynamic and the content as well. So I tried all possible ways to load the correct and accurate height of the parsed link however it's not getting the accurate result.

Below is my code:

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;
    });
});   

Did anyone experienced that before and have the correct solution to return dynamically the iframe height with 100% accuracy.

Note also neither CSS has resolved the issue nor the height attribute.

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