Closing a Lightbox from an iFrame
This is a follow up post to an article I wrote a few weeks ago about Lightbox Using iFrames Instead of AJAX.
That article described how to use an iFrame to display content in a Lightbox without using AJAX. There are advantages to this and you can read about them at the link above.
Traditionally a Lightbox could be closed using the code below:
-
<a href="#" class="lbAction" rel="deactivate">Close Lightbox.</a>
This code will only work if the link is being called from the same window that the lightbox is defined in, which presents a problem with our iFrame Lightbox because the iFrame is a separate window and knows nothing about the Lightbox defined in the parent.
Two parts are required to achieve closing a Lightbox from an iFrame. The first is a JavaScript function in the parent that can be called from the child window(iframe).
Parent Code
-
function closeLightbox() {
-
lightbox.prototype.deactivate();
-
}
The second is the call in the child window to the parent function closeLightbox
iFrame(child) Code
-
window.parent.closeLightbox();
Throw the above code into a link or button click and the Lightbox will be closed.
Download Complete Source (includes demo)
lightbox-iframe2.zip (15k)
Special thanks to Manuel Ribeiro. This code is based off of his implementation.

My name is Noah Everett. I live in Tulsa, OK. I started 