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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:17:05+00:00 2026-06-02T16:17:05+00:00

I forgot to include ‘run multiple times in one page’ on my last question

  • 0

I forgot to include ‘run multiple times in one page’ on my last question located here: Create iframe with javascript appending to a div

I need to run the code on multiple div’s within the same page. Right now the code below only runs once on the last div. For example if I have 3 div’s, all 3 should have an iframe appended to it. Regular javascript. Trying not to use JQuery.

window.onload = function(){
var link = "http://www.somesite.com"
var iframe = document.createElement('iframe');
iframe.frameBorder=0;
iframe.width="300px";
iframe.height="250px";
iframe.id="randomid";
iframe.setAttribute("src", link);
document.getElementById("ad54").appendChild(iframe); //<--this id will be dynamically generated to match div's
}


<div class="ad" id="1"></div>
<div class="ad" id="2"></div>
<div class="ad" id="3"></div>

EDIT: Tested in IE9, Chrome, Safari, Firefox and opera. This code works. No JQuery or loops needed. This code will create the iframe wherever you use it.

var link = "http://www.somesite.com"
document.write(iframe);
var myIframe = parent.document.getElementById("randomid");
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-02T16:17:06+00:00Added an answer on June 2, 2026 at 4:17 pm
    window.onload = function() {
      var elements = document.getElementsByTagName('div');
      for (var i = 0; i < elements.length; i++) {
        append_iframe( elements[i] );
      }
    }
    
    function append_iframe( div ) {
        var link = "http://www.somesite.com"
        var iframe = document.createElement('iframe');
        iframe.frameBorder=0;
        iframe.width="300px";
        iframe.height="250px";
        iframe.id="randomid";
        iframe.setAttribute("src", link);
        div.appendChild(iframe);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One example is described here . But the author apparently forgot to include the
I forgot to include the programming language (It should be in the C language).
I forgot the name of that application tool. anyone here remembers it? It let's
EDIT Sorry I forgot the most important part here. Each key can have more
[Update]: Forgot to include ComponentArt... Hi, An interaction designer employed by the client I
I forgot to include Core Data, and now I've completed half of the project
I have created one simple GWT application.I have created build.xml. But when I run
EDIT: forgot to include my environment info... Win7x64, RubyInstaller Ruby v1.9.1-p378 EDIT 2: just
I have the following XML: <employees> <employee> <!--forgot to include an attribute--> <name>John</name> <jobs>
I am fairly new to Java programming and was following a tutorial located here:

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.