Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I'm trying to add a 'close' button inside of an html page that I'm using lightbox2 with (via iframe, i.e. "rel=lightframe"). I've tried adding some jquery code to the head of the embedded HTML page, attaching a click event to the button I've put in my HTML content. But, even though I can get this to trigger something stupid like an alert box, it will not close the lightbox window when I attach "Lightbox.end('forceClose'); return false;" to it instead. What am I doing wrong?
Thanks!
Best,
Dave
Comments
Comment #1
stella CreditAttribution: stella commentedIt's not possible to do this. Browsers don't allow it as a means to help prevent cross-site scripting.
If you have control over the html content being displayed in the lightbox2, and if it is on the same domain as the page where the lightbox is being opened, then you could try
rel="lightmodal"
. For this to work in all browsers with no unexpected problems or errors, the html code in the modal dialog should not include<html>
,<body>
, or similar tags. This is because the content displayed in a "lightmodal" is placed inside a div in the current page. However, because it's inside the current page and not an iframe, it should be possible to close the lightbox from within the loaded page.Cheers,
Stella
Comment #2
dubitable CreditAttribution: dubitable commentedHi Stella,
Thanks for the quick response. I figured as much; but I appreciate you confirming this for me.
Thanks!
Best,
Dave
Comment #3
Leksat CreditAttribution: Leksat commentedDon't sure it will work for all browsers...
Add javascript function (global) in your main window which will close lightbox. Like this:
Now you can create button in your iframe. Like this:
<input type="button" onclick="javascript: window.parent.close_iframe(); return false;" value="Close">
The main thing is
window.parent.close_iframe();
.Comment #4
cgoren CreditAttribution: cgoren commentedHi,
Try adding onclick="parent.Lightbox.end('forceClose');" to the link.
Enjoy
Chen @ Creative Team