Solved

How do I close an IFRAME insde the IFRAME?

Posted on 2009-05-07
6
190 Views
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?
0
Comment
Question by:pmsguy
  • 2
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:Ronb23
Comment Utility
Inside the iFrame, add a JavaScript function
<script>
function closeIframe() {
   var iframe = document.getElementById('someid');
   iframe.parentNode.removeChild(iframe);
}
</script>

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

hope this helps.
0
 

Author Comment

by:pmsguy
Comment Utility
OK, The problem is the calling program is NOT on the same domain as the IFRAME.

From my PC is call a program on www.someserver.com

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

Expert Comment

by:Ronb23
Comment Utility
Let me have a better understand of your setup:
- There is server1 that's hosting www.server1.com
- There is server2 that's hosting www.server2.com
- Server2 have an iFrame that's calling to display www.server1.com
- On your PC, you have a program or a local webpage? that's calling www.server2.com in an iFrame

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

Thanks
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:pmsguy
Comment Utility
Yes that is correct
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
Comment Utility
pmsguy,

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.

b0lsc0tt
0
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
Thanks for the fun question, the grade and the points.
bol
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now