简体   繁体   English

iframe中的图片在主窗口中弹出灯箱

[英]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. 我在iframe(不是跨域)中放置了图片库,并希望使用Lightbox在主框架中显示popupdiv。 Because right now when the image in the iframe is clicked, the popup div just covers the iframe. 因为现在当单击iframe中的图像时,弹出div仅覆盖iframe。

I think it might have something to do with setting target="_top", but that doesn't quite do the trick. 我认为可能与设置target =“ _ top”有关,但这并不能解决问题。 Setting the window.top location to my main url just causes the page to go to that url. 将window.top位置设置为我的主URL只会导致页面转到该URL。

<iframe> cannot access its parent contents unless the parent frame provides a co-operative Javascript. 除非父框架提供合作的Javascript,否则<iframe>无法访问其父内容。

Instead of embedding your gallery directly via <iframe> you should embed it using a helper Javascript. 与其直接通过<iframe>嵌入图库, <iframe>使用辅助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. 然后,此帮助程序Javascript将通过postMessage()<iframe> Javascript通信,并且该帮助程序Javascript将在顶层执行所需的DOM操作,以便在顶层框架中打开覆盖<div>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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