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

stella’s picture

Status: Active » Closed (works as designed)

It'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

dubitable’s picture

Hi Stella,

Thanks for the quick response. I figured as much; but I appreciate you confirming this for me.

Thanks!

Best,
Dave

Leksat’s picture

Status: Closed (works as designed) » Needs review

Don't sure it will work for all browsers...

Add javascript function (global) in your main window which will close lightbox. Like this:

function close_iframe() {
  $('#bottomNavClose').click();
}

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();.

cgoren’s picture

Hi,

Try adding onclick="parent.Lightbox.end('forceClose');" to the link.

Enjoy
Chen @ Creative Team