Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
Cómo analizar la respuesta html de fetch () API a iframe

Estoy tratando de mostrar una página web en un iFrame usando la API fetch (), donde obtengo la URL del usuario y luego muestro la página en un iFrame como si estuviera alojado localmente, para que pueda usar JavaScript para trabajar en el página del iFrame sin problemas de origen cruzado.

Lo que estoy buscando es redirigir la respuesta al iframe usando srdoc.

El código para la página html está a continuación:

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

Esta es la función javascript:

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

Obviamente, con la respuesta de análisis no obtengo el resultado sino solo "[Respuesta del objeto]"; ¿Alguna sugerencia sobre cómo analizar la respuesta de fetch API() al iFrame?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!