简体   繁体   中英

Lightbox popup in main window from image in iframe

I have an image gallery placed in an iframe (not cross domain) and would like to use Lightbox to show a popupdiv in the main frame. Because right now when the image in the iframe is clicked, the popup div just covers the iframe.

I think it might have something to do with setting target="_top", but that doesn't quite do the trick. Setting the window.top location to my main url just causes the page to go to that url.

<iframe> cannot access its parent contents unless the parent frame provides a co-operative Javascript.

Instead of embedding your gallery directly via <iframe> you should embed it using a helper Javascript. Then this helper Javascript would communicate with <iframe> Javascript via postMessage() and the helper Javascript would do the required DOM manipulation on top level for opening an overlay <div> in the top level frame.

https://developer.mozilla.org/en/DOM/window.postMessage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM