How do I close an IFRAME insde the IFRAME?

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?
Who is Participating?
b0lsc0ttConnect With a Mentor IT ManagerCommented:

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.

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.
pmsguyAuthor Commented:
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.
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

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.

pmsguyAuthor Commented:
Yes that is correct
b0lsc0ttIT ManagerCommented:
Thanks for the fun question, the grade and the points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.