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 6813125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:32:01+00:00 2026-05-26T20:32:01+00:00

If I have a page which contains an iframe: <iframe src=blank.html id=frame></iframe> and I

  • 0

If I have a page which contains an iframe:


<iframe src="blank.html" id="frame"></iframe>

and I run the following javascript:


var iframe = document.getElementById("frame");
var content = iframe.contentDocument || iframe.contentWindow;
content = content.documentElement || content.document;
content.innerHTML = "Test";

my iframe ends up with the content “Test”. However, if I create the iframe in script (e.g.)


var iframe = document.createElement("iframe");
iframe.id = "frame";
iframe.src = "blank.html";
document.body.appendChild(iframe);

and then run the first snippet, I end up with a blank iframe. I've noticed that I do get a flash of the content I tried to set - is there an event I can subscribe to on the iframe to let me know it's okay manipulate (e.g. its DOM ready event?)

  • 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-05-26T20:32:01+00:00Added an answer on May 26, 2026 at 8:32 pm

    It flashes because you updating the DOM before its been set to blank.html;

    var iframe = document.createElement("iframe");
    iframe.id = "frame";
    iframe.src="about:blank"; //or blank.html
    iframe.onload = function() {
       var domdoc = iframe.contentDocument || iframe.contentWindow.document;
       domdoc.write("Test");
       alert("..or..")
       domdoc.body.innerHTML = "<em>Cake</em>";    
    }
    document.body.appendChild(iframe);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML page (say welcome.html) which contains an iframe to a page
I have a page that contains an iframe that gets loaded using Javascript: index.html
In JavaScript, let's say we have a main page ( main.html ) which contains
I have the following scenario where I have a page say parentPage.html, which contains
I have a page P1 loading from site S1 which contains an iframe. That
I have a page which contains a html.RenderPartial, that renders an ASP.NET MVC partial
I have a html page which contains nested frameset (don't ask why, I'm only
I have a main page which contains a simple iframe. Iframe source = a
I have a page which contains several vimeo videos, embedded in the standard iframe
I have a JSP page which includes an iframe , Iframe contains the image

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.