Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

making an ifram close itself

I'm sure this should be really simple but for some reason I can't get it to work.
I have a text link and I want it to close the iframe it is in.
I have <a href="javascript:onClick=self.close()">Close</a>
but it doesn't work. Can anyone tell me why and tell me a way which will work?

Thanks,
H
0
wjdashwood
Asked:
wjdashwood
  • 2
3 Solutions
 
p_parthaCommented:
As far as my knowledge goes,iframe is a part of the page, u cannot close the iframe, although u can hide the iframe

give a iframe an id like this..

<iframe id='test' blah blah..


and when u want to hide it, just say
document.getElementById("test").style.display='none'

Hope i am clear

Partha
0
 
gam3r_3xtr3m3Commented:
its an iframe. it won't close itself. but you can use CSS to make it vanish.

main
------
<iframe src="iframe.html" id="iframe1"></iframe>

iframe.html
-------------
<a href="#" onClick="window.top.document.getElementById("iframe1").style.display='none';">Close frame</a>
0
 
gam3r_3xtr3m3Commented:
error:
here's a correct version:

main
------
<iframe src="iframe.html" id="iframe1"></iframe>

iframe.html
-------------
<a href="#" onClick="window.top.document.getElementById('iframe1').style.display='none'; return false;">Close frame</a>

0
 
wjdashwoodAuthor Commented:
well, you are all right, thats how i did it in the other, just me being stupid! I needed to hide it, not close it.

Thank you
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now