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

128
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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