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

284
Visualizações
React / Nextjs page as an iframe on another page with resizing

I am trying to embed my nextjs / react website inside a wordpress site. That works so far, but it does not size the iframe properly.

I found a solution, which is for native js, which I need to add to my react app

  function sendHeight() {
    if (parent.postMessage) {
      // replace #wrapper with element that contains 
      // actual page content
      var height = document.getElementById('calendar-wrapper').offsetHeight;
      parent.postMessage(height, '*');
    }
  }

  // Create browser compatible event handler.
  var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
  var eventer = window[eventMethod];
  var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

  // Listen for a message from the iframe.
  eventer(messageEvent, function (e) {

    if (isNaN(e.data)) return;

    sendHeight();

  }, false);

The question which I have is how can I run this properly in my functional component?

For instance if the functional component looks like this:

const Home = () => {
    return (
        <div id="calendar-wrapper">
    ...
}

I am not sure when to call the eventer in the react way.

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