Solved

Javascript iframe close

Posted on 2011-03-21
5
632 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

831 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