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

  • Home
  • SEARCH
  • 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 7956067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:53:02+00:00 2026-06-04T03:53:02+00:00

I need to insert an iframe into a div using javascript. I need this

  • 0

I need to insert an iframe into a div using javascript. I need this written in javascript so I can use the code in a greasemonkey script (and greasemonkey only allows for javascript).

The greasemonkey script will be inserting AOL’s search bar into various websites. I’ve included the working HTML code below so you can test it out to see what the end result is when this works.

Here is exactly what I need to do, written in HTML:

<div style="overflow: hidden; width: 564px; height: 43px; position: relative;">
<iframe src="http://aol.com" style="border: 0pt none ; left: -453px; top: -70px; position: absolute; width: 1440px; height: 775px;" scrolling="no"></iframe>
</div>

I need to make that HTML code work in greasemonkey, which requires it being written in javascript. Here is what I’ve got so far (with my final question beneath the “pseudo-code”):

var makeIframe = document.createElement("iframe");
makeIframe.setAttribute("src", "http://aol.com");
makeIframe.setAttribute("scrolling", "no");
makeIframe.setAttribute("border", "0pt");
makeIframe.setAttribute("border", "none");
makeIframe.setAttribute("left", "-453px");
makeIframe.setAttribute("top", "-70px");
makeIframe.setAttribute("position", "absolute");
makeIframe.setAttribute("width", "1440px");
makeIframe.setAttribute("height", "775px");
makeIframe.setAttribute("scrolling", "no");

var makediv = document.createElement("div");
makediv.setAttribute("height", "43px");
makediv.setAttribute("width", "564px");
makediv.setAttribute("position", "relative");
makediv.setAttribute("overflow", "hidden");

I already know how to either insert the iframe OR insert the div into the source code of the sites I need to insert it into, by doing this:

var getRef = document.getElementById("div-id-to-insert-element-before");
var parentDiv = getRef.parentNode;
parentDiv.insertBefore(iframe OR div, getRef);

What I CAN’T figure out how to do, is how to write the iframe INTO the div and then insert that div into the source code. That very last code snippet works for inserting either the div or the iframe into the source code, but I need the iframe inside the div, and then for that div to be inserted into the source code (using that last code snippet).

Any ideas?

  • 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-04T03:53:05+00:00Added an answer on June 4, 2026 at 3:53 am

    1- you can use element.appendChild

    makediv.appendChild(makeIframe);
    

    2- Or append iframe as html into div like this,

    makediv.innerHTML = '<iframe src="http://aol.com" style="border: 0pt none ;'+ 
                        'left: -453px; top: -70px; position: absolute;'+ 
                        'width: 1440px;'+ 
                        'height: 775px;" scrolling="no"></iframe>';
    

    than insert makediv to where you want,

    var getRef = document.getElementById("div-id-to-insert-element-before");
    var parentDiv = getRef.parentNode;
    parentDiv.insertBefore(makediv, getRef);
    

    UPDATE:

    You cannot set style with setAttribute function,

    var makeIframe = document.createElement("iframe");
    makeIframe.setAttribute("src", "http://aol.com");
    makeIframe.setAttribute("scrolling", "no");
    makeIframe.style.border = "none";
    makeIframe.style.left =  "-453px";
    makeIframe.style.top = "-70px";
    makeIframe.style.position = "absolute";
    makeIframe.style.width = "1440px";
    makeIframe.style.height = "775px";
    
    var makediv = document.createElement("div");
    makediv.style.height = "43px";
    makediv.style.width = "564px";
    makediv.style.position = "relative";
    makediv.style.overflow = "hidden";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to insert html code like this in my zend form: <div class=myClass1
I need to insert records into a table that has no primary key using
I need to wait for document readyness in my JavaScript, to insert a div
I need to produce a small script that users can insert in to their
I need an insert statement that will do roughly this: INSERT INTO tblContent(postTitle, postBody,
I need to insert 800000 records into an MS Access table. I am using
Need to insert selected text on the page into textarea. There must be some
I need to insert a div in the DOM after the html tag. It
I need to insert some data in bulk into an azure storage table. As
The need to insert values from 3 tables into another table called myTable .

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.