Solved

Javascript iframe close

Posted on 2011-03-21
5
636 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 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…
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)

729 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