Solved

Javascript iframe close

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now