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

305
Vistas
How to parse html response from fetch() API to iframe

I am trying to display a web page into an iFrame using fetch() API, where I get the url from the user and then display the page into an iFrame as if it is locally hosted, so that I can use javascript to work on the page from the iFrame without cross-origin issues.

What I am looking for is to get the response redirected into the iframe using srdoc.

Code for html page is below:

    <form method="POST">
                        <iframe id="frame" style="resize: both;width: 350px; height:500px;"></iframe>
                        <button type="button" onClick="retrieve()">Retrieve</button>  
                        </form>
                    </div>  
                     <div id="textarea">
                        <textarea id="` + tab_id + `" class="form-control" placeholder="Enter your source text here..." rows="20" onchange="change_textarea('` + tab_id + `')" onfocus="set_focus(this)" style="resize: vertical; min-height:35px;" readonly></textarea>
                    </div>  
                </div> 
            </form>

This is the javascript function:

function retrieve(){
    
    let headers = new Headers();

  headers.append('Content-Type', 'application/json');
  headers.append('Accept', 'application/json');
  headers.append('Origin', 'http://localhost:8080');
  headers.append('Access-Control-Allow-Origin', 'http://localhost:8080');
  headers.append('Access-Control-Allow-Credentials', 'true');
    console.log(headers);

    url = document.getElementById("tt").value;
    fetch(url, {
        mode: 'no-cors',
        credentials: 'include',
        method: 'POST',
        headers: headers
    })
    .then((response) => {
        document.getElementById("frame").srcdoc = response;  
    }) 
}

Obviously, with parsing response I don't get the result but just "[Object Response]"; Any suggestions on how to parse the response from fetch API() to the iFrame?

about 4 years ago · Juan Pablo Isaza
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