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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:46:04+00:00 2026-06-05T15:46:04+00:00

In my extension, I have a content script that creates a <div> containing an

  • 0

In my extension, I have a content script that creates a <div> containing an <iframe> inside the current webpage (e.g. http://www.google.com). I load a page into the iframe, but the content has to be dynamic, so I post a bunch of HTML to the background page first using sendRequest. The iframe page then queries the background page (again with sendRequest), gets the HTML and adds it to the page’s body.

The issue is that the iframe is not sized correctly when the dynamic content is added, so it has scrollbars. I would like to do something like this:

iframe.addEventListener("DOMContentLoaded", function(event) {
    div.style.height = iframe.style.height = iframe.contentDocument.body.scrollHeight;
    div.style.width = iframe.style.width = iframe.contentDocument.body.scrollWidth;
}, false);

Unfortunately I have two problems with this. First of all, the DOMContentLoaded event is never fired (why?). Secondly, I presumably won’t have access to iframe.contentDocument anyway since iframe is loading from a different domain.

I could have the iframe use sendRequest to post its size somewhere where the hosting page can get its hands on it. However, I am using the same code to insert the iframe into a popup window as well, so there’s no easy way to send the request (since it will use chrome.tabs.sendRequestfor the content script but chrome.extension.sendRequest for the popup window).

Any ideas about how to do this?

  • 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-05T15:46:05+00:00Added an answer on June 5, 2026 at 3:46 pm

    Poked around a bit more and found a solution. The iframe, once it has loaded the dynamic content, calls:

    var size = { height: document.body.scrollHeight, width: document.body.scrollWidth };
    top.postMessage(JSON.stringify(size), "*");
    

    The parent window contains:

    window.addEventListener("message", function(event) {
        var size = JSON.parse(event.data);
        iframe.style.height = div.style.height = size.height + "px";
        iframe.style.width = div.style.width = size.width + "px";
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Google Chrome Extension, I have a Content Script (content.js) and a Background
I have created a simple Google chrome extension that overrides CSS classes using the
I have a simple image upload script that uses SimpleImage.php (http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/) to resize and
I have a Google Chrome extension that opens a Twitter Bootstrap dialog (using JQuery
In my Google Chrome extension, I have a content_script that I want to communicate
I am writing a chrome extension that is a 'content script' I want to
Just curious, I've noticed that some php files have extension 'class.php' or 'html.php'. What
I have an extension method that I'm trying to use where you can use
I have chrome extension in that I am trying to use GWT RPC. Cant
I have created a Chrome extension that uses the hotkeys [Alt]+[0...9] only to discover

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.