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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:59:12+00:00 2026-06-11T17:59:12+00:00

I have a content script that runs from my chrome extension. this script injects

  • 0

I have a content script that runs from my chrome extension.
this script injects an iframe to the body of the current page.
i want to have the possibility to close the iframe from within the iframe.
how do i do this?
when i searched this issue on the web, almost each solution uses the window.parent.document property which for some reason is undefined in my case. any ideas?

EDIT – Code Sample:

in the HTML of the iframe:

<script type="text/javascript">
        function frameClose() {
            var windowFrames = window.parent.frames;
            for (var i = 0; i < windowFrames.length; i++) {
                var aFrame = windowFrames[i];
                if (aFrame.name == 'myFrame') {
                    alert('in frame');
                    // WHAT TO DO HERE?
                    // window.parent.document is undefined
                    // aFrame.parentNode.removeChild(aFrame); - THIS DOES NOT WORK ALSO
                    break;
                }
            }
        }
    </script>

this is how i inject the iframe:

Extension.js

chrome.browserAction.onClicked.addListener(function(tab) {

    chrome.tabs.executeScript(null, {
        file : "/js/PushIFrame.js"
    }, function() {
        if (chrome.extension.lastError) {
        }
    });
});

and in PushIFrame.js i have:

chrome.extension.sendMessage({
    action: "pushFrame",
    source: pushIframe(document)
});

function pushIframe(document) {
    var existingFrame = document.getElementById('bmarkFrame');
    if (existingFrame == null) {
        var temp = document.createElement('iframe');
        temp.id = 'myFrame';
        temp.name = 'myFrame';
        temp.setAttribute('scrolling', 'no');
        temp.setAttribute('allowtransparency', 'true');
        temp.style.border = 'none';
        temp.style.height = '100%';
        temp.style.width = '100%';
        temp.style.position = 'fixed';
        temp.style.zIndex = 99999999;
        temp.style.top = 0;
        temp.style.left = 0;
        temp.style.display = 'block';
        temp.src = 'https://www.mysite.com/';

        document.body.appendChild(temp);
    }
    else {
        existingFrame.style.display = 'block';
    }
}
  • 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-11T17:59:13+00:00Added an answer on June 11, 2026 at 5:59 pm

    Let the content script (say PushIframe.js) bind a message event to the main frame. Then, whenever you want to hide the iframe, call parent.postMessage to notify the main frame. This message is received by the content script, from where you can hide the frame (as defined in your function pushIframe).

    // PushIframe.js:
    addEventListener('message', function(ev) {
        if (ev.data === 'closeIframe') {
            pushIframe(document); // Your code
        }
    });
    
    // Iframe:
    <script>
    function frameClose() {
        parent.postMessage('closeIframe', '*');
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this content script that downloads some binary data using XHR, which is
In my extension, I have a content script that creates a <div> containing an
I have a web page that loads in an IFRAME, that runs correctly in
I have script that reads remote file content and writes it to local server.
I have a PHP script that does the following: Uses file_get_contents() to get content
I have a ColdFusion script that does: <cfset content = replace(content,&##147;,,all)> Which replaces &147;
I have a nant script that ... 1. takes the content of disc-file 2.
I have a bash script that sources contents from another file. The contents of
I have a script which collects an image, link and some text content from
This is the script I have written for gzipping content on my site, which

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.