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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:20:50+00:00 2026-06-13T16:20:50+00:00

I am trying to include an iframe on a Drupal page. So far I

  • 0

I am trying to include an iframe on a Drupal page. So far I successfully included the frame but the height resize function that I wrote only works in Internet Explorer. My goal is to make resize work inFirefox and Chrome as well. I searched the Internet but I couldn’t find what I was looking for. Long story short, I want my frame to automatically resize height itself.

This is what I did so far (this is the code of the HTML page included in Drupal):

<script type="text/javascript">
    function resize() {
        var iframe = document.all.icw;
        document.getElementById("icw").style.height = iframe.document.body.scrollHeight + "px";
    }
</script>
<iframe id="icw" src="XXXXX" width="100%" scrolling="no" onload="resize()">

I understand that if the iframe lives on another domain the solution may be more difficult due to permissions. Is that correct?

These are the errors I get in Chrome and Firefox:

Chrome: Cannot read property ‘body’ of undefined

Chrome: JavaScript attempt to access frame with URL XXX from frame with URL YYY. Domains, protocols and ports must match.

Firefox: document.all is undefined

EDIT: What if I want to change one of the iframe element? In my case I need to change a textbox value. I understand I must do that when the page is loaded but I can’t find a solution. No matter where I put the code I always a get a

Cannot call method ‘getElementById’ of undefined

when I try to access the iFrame textbox.

EDIT2: Asked a new question since they weren’t related.

  • 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-13T16:20:53+00:00Added an answer on June 13, 2026 at 4:20 pm

    This solution works even cross-domain as long as you have access to both. There are a bunch of edge cases, but at least you can start with this. You can also add timer event to make sure iFrame is always a correct size so you never have scrollbar. Keep in mind this only works with browser supporting HTML5 due to the use of postMessage.

    Inside iFrame

    function resize(){
        var body = document.body,
        html = document.documentElement,
        height = body.offsetHeight;
        if(height === 0){
            height = html.offsetHeight;
        }
        parent.postMessage({'action':'RESIZE', 'height':height}, '*');
    }
    

    Parent

    function handleMessage(e) {
        if (e.data.action == 'RESIZE') {
            var targetHeight = e.data.height;
            $('#iFrame').height(targetHeight);
        }
    }
    
    window.addEventListener("message", handleMessage, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to include a Facebook share iframe on a site that's served using
I'm trying to customize a wordpress page to include an iframe which give the
I am trying to include a Facebook like button iFrame that has PHP in
I'm trying to include a vCard export function in an existing page full of
I am trying to include a .php file that will generate a form for
I am trying to include an IF within my LET in LINQ but i
I'm trying to include a hyperlink in my email but it is just showing
I am trying to include <% @using System.Web.Script.Serialization%> but it is giving me error
I am trying to create an iframe with a height of 100% and a
I am trying to include atomic in my C++ pthread program. #include <atomic> But,

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.