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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:46:33+00:00 2026-05-27T05:46:33+00:00

Plain JS – please no jQuery suggestions – it is for a bookmarklet that

  • 0

Plain JS – please no jQuery suggestions – it is for a bookmarklet that needs to use as plain JS as possible.

I hope someone KNOWS the answer since I cannot reliable create a fiddle.

This code will run in the scope of the page it is inserted in – it works perfectly in Fx6-9, safari and latest Chromes on Windows XP and OSX – Only IE gives me undefined when I try to access the iFrame

var zContainer = document.getElementById('zContainer');
if (zContainer==null) {
  zContainer = document.createElement("div");
  zContainer.id="zContainer";
  document.body.appendChild(zContainer);
}    

var zStuff = {}; // minimise window var footprint
zStuff.html = '<body>Hello</body>';
if (!zFrame) { // did we already have one?
  zFrame = document.createElement("iframe");
  zFrame.id="zIframeId"; zFrame.name="zIframeName"; zFrame.frameBorder="0";
  zIFS = zFrame.style; zIFS.border="0"; zIFS.width="500px"; zIFS.height="500px"; zIFS.backgroundColor="white"; zIFS.display="block";
  zContainer.appendChild(zFrame); // append to div

  zFrame = window.frames["zIframeName"]; // undefined in IE8 !!!!!
  // zFrame = document.getElementById("zIframeId"); // undefined in IE8 !!!!!

  zFrame.src="javascript:'<body></body>'"; // initialise body
  zFrame.document.write(zStuff.html); // or zFrame.contentDocument.write
  zFrame.document.close(); 
  // zFrame.document.body.innerHTML=zStuff.html; // also does not work

//  zFrame.src="javascript:'"+zStuff.html+"'"; // alternative method - either one works in Fx/Chrome
}

Thanks for any hints and for not voting this down. I hope the SO community will be as
helpful to me as I have been to it over the last year and a half…


Update – since the code I posted had some remnants of desperation, I changed it to

if (!zFrame) { // did we already have one?
  zFrame = document.createElement("iframe");
  zFrame.id="zIframeId"; zFrame.name="zIframeName"; zFrame.frameBorder="0";
  zIFS = zFrame.style; zIFS.border="0"; zIFS.width="500px"; zIFS.height="500px"; zIFS.backgroundColor="white"; zIFS.display="block";
  zContainer.appendChild(zFrame); // append to div

  zFrame.src="javascript:'<body></body>'"; // initialise body

  zFrame.document.write(zStuff.html); // or zFrame.contentDocument.write
  zFrame.document.close(); 
}

the above now replaces the page I am on with the code in the zStuff.html
instead of replacing only the iFrame content – it also broke in Fx

Now I have to do this in Fx which IE also does not mind but still replaces the window and not the iFrame

if (!zFrame) {
  zFrame = document.createElement("iframe");
  zFrame.scrolling="no"; zFrame.id="zIframeId"; zFrame.name="zIframeName"; zFrame.frameBorder="0";
  zIFS = zFrame.style; zIFS.border="0px none"; zIFS.width="549px"; zIFS.height="510px"; zIFS.backgroundColor="white"; zIFS.display="block";
  zDRContainer.appendChild(zFrame);
  zFrame.src="javascript:'<body></body>'";
  setTimeout(function() {
    var zFrame = window.frames["zIframeName"]; // this is needed for the document.write
    zFrame.document.write(zStuff.html); 
    zFrame.document.close();
  },100); 
}
  • 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-27T05:46:34+00:00Added an answer on May 27, 2026 at 5:46 am

    The hack I suggested in chat:

    var a = setInterval( function(){
    
        try{
        zFrame.contentWindow.document.write(zStuff.html);
        zFrame.contentWindow.document.close();
        clearInterval(a);
        }
        catch(e){}
    
    }, 10 );
    

    Since it is not known when IE allows accessing contentWindow properties, this will keep trying until it is allowed.

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

Sidebar

Related Questions

Please explain using plain english why we need and why we use Interface in
If I use: String plain = Html.fromHtml(html).toString; to render simple 'html' that contains: <!doctype
I am using plain old school Javascript - So no jQuery responses please!. I
I have an plain simple java application that use spring 2.5.5 and hiberate 3.3.1.GA.
I came across this plain js ajax upload code (it seems that jquery $.post
We are currently storing plain text passwords for a web app that we have.
It is possible in plain Java to override a method of a class programmatically
in plain english can you please explain to me what does this line mean:
I've a plain UITableView (not grouped) that I want to add a dropshadow to
I have a txt plain file that has a list of numbers. One number

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.