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.
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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.