How do I close an IFRAME insde the IFRAME?

Posted on 2009-05-07
Last Modified: 2012-05-06
How do I close an IFRAME insde the IFRAME?

I want the user to click OK inside the IFRAME to close the IFRAME.

How do I accomplish this?
Question by:pmsguy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2

Expert Comment

ID: 24329898
Inside the iFrame, add a JavaScript function
function closeIframe() {
   var iframe = document.getElementById('someid');

And then add a button or link to close that iFrame:
<a href="javascript: closeIframe()">Close</a>

hope this helps.

Author Comment

ID: 24329978
OK, The problem is the calling program is NOT on the same domain as the IFRAME.

From my PC is call a program on

I get an error "Permission denied to get property..." when I try to close the IFRAME from my program on my PC.

Expert Comment

ID: 24330394
Let me have a better understand of your setup:
- There is server1 that's hosting
- There is server2 that's hosting
- Server2 have an iFrame that's calling to display
- On your PC, you have a program or a local webpage? that's calling in an iFrame

Let me know if I have this right. If not, please explain the setup and we'll go from there.

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 24330863
Yes that is correct
LVL 54

Accepted Solution

b0lsc0tt earned 500 total points
ID: 24331873

It won't work.  The browser prevents it.  It is called cross site or cross domain scripting.  Javascript can't change content on another domain, server or different protocol.  If your code is on your domain and the iframe is in code on another domain then you can't do it.

Let me know if you have any questions or need more information.

LVL 54

Expert Comment

ID: 24337427
Thanks for the fun question, the grade and the points.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question