简体   繁体   English

Fancybox:从iframe中调用父级函数

[英]Fancybox: call a function in parent from within iframe

I am using Fancybox 2. 我正在使用Fancybox 2。

I am trying to find a way to information from the parent from within the iframe window. 我试图在iframe窗口中找到一种从父级获取信息的方法。 Here is my situation: 这是我的情况:

  1. open Fancybox iframe from the parent 从父级打开Fancybox iframe

  2. after the iframe is opened, user clicks on a button. 打开iframe后,用户单击一个按钮。 This click needs info from the parent, for which I hope to call a function in the parent. 此单击需要来自父级的信息,我希望为其提供父级的函数。 Please note that clicking on this button should not close the iframe. 请注意,单击此按钮不应关闭iframe。

Is this something doable in Fancybox 2? 这在Fancybox 2中可行吗? I read many posts at SO and am unable to figure this out. 我在SO上阅读了许多帖子,无法弄清楚。

Thanks for any help!!! 谢谢你的帮助!!!

If in your parent page you have this function 如果在父页面中具有此功能

function fnParent() {
    // returns some data 
};

... from within the iframed page you just need to call that function like : ...在iframed页面中,您只需要调用以下函数:

parent.fnParent();

Notice that if you open fancybox in iframe mode, whatever interaction or click events inside the iframe will never close fancybox unless one clicked element calls the parent.jQuery.fancybox.close() method. 请注意 ,如果你开的fancybox中iframe模式,无论交互或click内部事件iframe永不闭幕的fancybox除非一个点击的元素调用parent.jQuery.fancybox.close()方法。

Also notice that the iframed page may need to have jQuery included and its own scripts and functions to process the response from the parent page. 还要注意,iframed页面可能需要包含jQuery以及它自己的脚本和函数来处理来自父页面的响应。

See JSFIDDLE 参见JSFIDDLE

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

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