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

303
Views
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
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!