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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:52:53+00:00 2026-06-10T09:52:53+00:00

I am trying to write a JS class to easily create Iframe HTML objects.

  • 0

I am trying to write a JS class to easily create Iframe HTML objects.
This is my code:

var Iframe = function (params) {
    var src = params.src || '';
    var appendTo = document.getElementById(params.appendId) || document.body;
    var iframe = document.createElement('iframe');
    iframe.src = src;
    if (typeof params.attrs != 'undefined') {
        for (attr in params.attrs) {
            iframe.attr = params.attrs[attr];
            alert('attr: ' + attr + "\nIframe.attr: " + iframe.attr);
            alert(params.attrs[attr]);
        }
    }

    appendTo.appendChild(iframe);

}

When the DOM loads:

var myIframe = new Iframe({
    src: 'http://www.example.com',
    appendId: 'iframeDiv',
    attrs: {height: '500px', id: 'ID'}
});

It alerts the expected values:

attr: height
Iframe.attr: 500px

and:

500px

But fails to set the arguments on the HTML, this is the generated source:

<div id="iframeDiv">
    <iframe src="http://www.example.com"></iframe>
</div>

What’s wrong?
How can I achieve this?

Thanks!

  • 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-10T09:52:55+00:00Added an answer on June 10, 2026 at 9:52 am
    iframe.attr = params.attrs[attr];
    

    I think you meant:

    iframe[attr] = params.attrs[attr];
    

    or:

    iframe.setAttribute(attr, params.attrs[attr]);
    

    You also forgot to declare attr, by the way.

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

Sidebar

Related Questions

I'm trying to write a class that will return a string of HTML with
I am trying to write a template class in C++ and getting this strange
I'm trying to write this custom addition class for very large integers, bigger than
I'm trying to write a class for this (forEach) tag. Here's the class: public
I am trying to write class that inherits from FMX TStyledControl. When style is
I'm trying to write a class in C++, but whenever I try to compile,
I'm trying to write a singleton class to hold the state of inputs from
I'm trying to write a generic class which contains a generic TObjectList< T >
I was trying to write up a class in c++, and I came across
I'm trying to write a Date class in an attempt to learn C++. I'm

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.