Solved

Javascript iframe close

Posted on 2011-03-21
5
634 Views
Last Modified: 2012-05-11
Hello,

I would like close an Iframe from an html button onclick event inside the iframe. I tried the below but no luck, any help is greatly appreciated!

<iframe id="xyz">
    <button type="submit" onclick="javascript:window.parent.closeFrame();</button>
</iframe>

0
Comment
Question by:cgray1223
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35186780
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35186782
0
 
LVL 19

Expert Comment

by:Rikin Shah
ID: 35186864
<iframe id="xyz">
    <button type="submit" onclick="javascript:document.getElementById('xyz').style.display='none';</button>
</iframe>

Open in new window

0
 
LVL 10

Accepted Solution

by:
khan_webguru earned 500 total points
ID: 35187189
Hello bro!

You need to assign an id to your iframe, like <iframe id="someid"...

Then you need a function to remove the iframe:

 
function closeIframe() [
   var iframe = document.getElementById('someid');
   iframe.parentNode.removeChild(iframe);
}

Open in new window


Finaly, you need to call it from the iframe, like:

 
<a href="javascript: window.parent.closeIframe()">Close</a>

Open in new window


Or you can forget the function and use a long link like this:

 
<a href="javascript: window.parent.document.getElementById('someid').parentNode.removeChild(window.parent.document.getElementById('someid'))">Close</a>

Open in new window


For more help you can view these blogs

http://forums.devarticles.com/javascript-development-22/overwrite-self-close-function-in-iframe-46277.html

http://www.webdeveloper.com/forum/showthread.php?t=105049

Hope this will help you to solve your problem.

Regards,

Asif Ahmed Khan
0
 
LVL 10

Expert Comment

by:khan_webguru
ID: 35300700
any success??
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

808 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