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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:25:25+00:00 2026-06-04T16:25:25+00:00

I have a dynamically created iframe made with regular javascript. It works great when

  • 0

I have a dynamically created iframe made with regular javascript. It works great when its called from a static page by regular means, but when called from a page loaded by Jquery, I get a ‘myIframe is null’ error.

var link = 'http://www.blah.com'
var iframe='<iframe class="adframe" id="randomnumberhere" name="widget" src="#" width="300" height="250" marginheight="0" marginwidth="0" frameborder="no" scrolling="no"></iframe>';

document.write(iframe);
var myIframe=parent.document.getElementById("randomnumberhere");
myIframe.height=250;
myIframe.width=300;
myIframe.src=link;
myIframe.style.border="0px";
myIframe.style.padding="0px";
  • 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-04T16:25:27+00:00Added an answer on June 4, 2026 at 4:25 pm

    I solved this one by adding a div with a unique id then append the iFrame to that div. It seems document.write can make the object, but appending to that element wasn’t happening. The working code is below.

    Have a dynamically created random number for the div in the html already there:

    <div id="randomid"></div>
    

    Then I made a function to append to that div with that specific id

    function makeFrame(){
    var link = 'http://blah.com'
    ifrm = document.createElement("IFRAME");
    ifrm.setAttribute("src", link);
    ifrm.style.width="300px";
    ifrm.style.height="250px";
    ifrm.style.border="0px";
    ifrm.style.padding="0px";
    document.getElementById('randomid').appendChild(ifrm);
    }
    makeFrame();
    

    This will only work if the div is already on the page. I couldn’t figure out a way to dynamically make the div and then append the iFrame to that div. Document.write made the div, but it couldn’t append the iFrame to that element. Perhaps a delay would make it work? Below is what I tried, but didn’t work.

    var iDiv='<div id="randomid"></div>';
    document.write(iDiv);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have dynamically created option elements with javascript. I double click an option from
I have problem with dynamically created image (JavaScript). I want to change the innerHTML
I have several dynamically created links and forms on one page named with IDs
I have dynamically created a xml string form a JSON object returned from server.
i have dynamically created table with string builder.. when i run this page background
I have some JavaScript code that dynamically injects an iframe in a given HTML
I have a dynamically created select option using a javascript function. the select object
I have a main page that include a javascript that was creating an iframe
please someone help out from this headaround problem of me; I have dynamically created
I have dynamically created HTML table clicking on its TH will reload the table

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.