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

130
Visualizações
How to check if iframe content is loaded in react

I have a collection of news articles from multiple sources which i try to display. Some of the websites don't allow their content loaded inside an iframe, so i want to check whether the content is being loaded and redirect to the original article if blocked.

When i try to locate the iframe with DOM it is undefined, when i try to do it with useRef same thing happens. Is there some way to check for successful connection or just the url in the iframe?

Here is the code:

export default function Article(){

// just getting the source url for the iframe

const url = window.location.href.split("=")[1]

const [ article, setArticle ] = useState();

useEffect(() => {
    Axios.get("http://localhost:8000/article?id=" + url).then(
        (response) =>{
            setArticle(response.data.link);
        }
    )
}, []);

// just getting the source url for the iframe

return(
    <div>
        <iframe id="frame" src={article}></iframe>
    </div>          
);
  

}

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use the onload event of an iframe.

export default function Article() {
  // just getting the source url for the iframe

  const url = window.location.href.split("=")[1];

  const [article, setArticle] = useState();

  useEffect(() => {
    Axios.get("http://localhost:8000/article?id=" + url).then((response) => {
      setArticle(response.data.link);
    });
  }, []);

  handleIfrmeLoad = () => console.log("iframe loaded");

  return (
    <div>
      <iframe id="frame" src={article} onload={handleIfrmeLoad}></iframe>
    </div>
  );
}
  
about 4 years ago · Santiago Trujillo 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