简体   繁体   中英

Fancybox: call a function in parent from within iframe

I am using Fancybox 2.

I am trying to find a way to information from the parent from within the iframe window. Here is my situation:

  1. open Fancybox iframe from the parent

  2. after the iframe is opened, user clicks on a button. 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.

Is this something doable in Fancybox 2? I read many posts at SO and am unable to figure this out.

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 :

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.

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.

See JSFIDDLE

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