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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:14:01+00:00 2026-05-15T19:14:01+00:00

Is it possible to create an Iframe using document.createElement(iframe); and then set a variable

  • 0

Is it possible to create an Iframe using document.createElement("iframe"); and then set a variable in the iframe’s window object such as a namespace?

I have tried doing something like this:

var Namespace = {}; 
var iframe = document.createElement("iframe"); 
iframe.src = "page.html"; 
document.body.appendChild(iframe);
var iwin = iframe.contentWindow || iframe.contentDocument.defaultView; 
iwin.Namespace = Namespace;

But in page.html I try to log Namespace and it throws an undefined error.

  • 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-15T19:14:01+00:00Added an answer on May 15, 2026 at 7:14 pm

    The same-origin policy is probably blocking you from doing this. This can also happen in some browsers if both pages use a file:// uri scheme.

    If the iframe and the outer windows will be using the same domain, this problem should go away once your code is on a server. Try serving it from localhost using apache to check, or test it with google chrome with same-origin policy disabled as per this post:

    Disable same origin policy in Chrome

    On the other hand, if the iframe needs to be at a different domain, or this needs to work with the file:// uri scheme, you’ll need to use some kind of workaround.

    One way to pass data into an iframe at another domain is via a fragment identifier in the iframe element’s src attribute, which will be visible in the iframe window’s ‘location’ object’s ‘hash’ property; for example:

    Outer page:

    <!doctype html>
    <html><head></head><body>
    <script>
      var Namespace = {foo:1, bar:2}; 
      var iframe = document.createElement("iframe"); 
      iframe.src = "frame.html#" + JSON.stringify(Namespace);
      document.body.appendChild(iframe);
    </script>
    </body></html>
    

    Inner page “frame.html”:

    <!doctype html>
    <html><head></head><body>
    <a href="#" onclick="alert(location.hash.substring(1))">click me</a>
    </body></html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script which loads content into a iframe using: document.GetElementById('iframeid').src = 'site.html';
Is it possible using jQuery to create an <iframe> element and append html content
i am able to create an iframe using appendChild, without jquery, is it possible
I have using colobox which is a jquery modal window to create a login/regiestration
Is it possible to create a REST web service using ASP.NET 2.0? The articles
Is it possible to create Selenium tests using the Firefox plugin that use randomly
Possible Duplicate: Create an Iframe from a Drupal Website I'd like to use an
Is it possible to add/create new history token from every class? I have the
I have a UI with a print button, i want to create an iframe
Is it possible to create an iframe on the background.html page in a google-chrome

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.