Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8197911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:50:23+00:00 2026-06-07T05:50:23+00:00

There are quite a few other posts on stackoverflow that ask nearly the same

  • 0

There are quite a few other posts on stackoverflow that ask nearly the same question, but in all the answers I’ve read so far, they don’t address how to essentially replace the entire document of the iframe, including the DOCTYPE and html tags.

I am retrieving the HTML for an entire page via a jQuery.ajax request and attempting to use the returned HTML as the new HTML of the iframe. Here’s an example of the HTML being returned from the ajax request:

<!DOCTYPE html>
<html lang="en-US">
    <head>
        <link rel="stylesheet" type="text/css" media="all" href="main.css">
        <title>Test Page</title>
    </head>
    <body>
        <h1>Heading</h1>
    </body>
</html>

I then inject this HTML into the iframe via:

$('#my-iframe').contents().find('html').html(returnedHtml);

As suggested on most of the other posts on this subject. However, when I inspect the contents of the iframe, the document is structured as follows:

<html>
    <link rel="stylesheet" type="text/css" media="all" href="main.css">
    <title>Test Page</title>
    <h1>Heading</h1>
</html>

Notice the lack of DOCTYPE, missing lang attribute on the html tag, missing head and body tags.

Any suggestions? (Note that just changing the iframe’s src attribute to the necessary url is not possible in this app due to various factors)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:50:24+00:00Added an answer on June 7, 2026 at 5:50 am

    Try some plain javascript instead:

    iframe = document.getElementById('my-iframe');
    iframe.contentWindow.document.open()
    iframe.contentWindow.document.write(returnedHtml);​
    

    FIDDLE

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there has been quite a few posts on this but all the
There are quite a few other questions on here that tell you how to
There are quite a few other questions similiar to this but none of them
Read this thread but didn't really answer my question and there were quite a
First of all, I know there are a few quite similar questions here on
I know there are quite a few libraries out there that that allow Twitter
I've seen quite a few posts on changes in .NET 3.5 SP1, but stumbled
There are quite a few questions on why local notification is not firing properly
There are quite a few of IRC server codes I am working on a
There is quite a few code samples on PayPal GitHub showing how to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.