开发者

Using Jquery Fancybox resize() function within an Iframe?

I am a beginner with Jquery and I am using Fancybox (type: if开发者_开发百科rame) within my PHP application.

Within the iframe, there is a form, once the user has filled & submitted the form, the Fancybox should resize so as to accomodate the data which will be relayed back once the formdata has been processed.

And I would also like the main page of the site to refresh once the user closes the Fancybox alert.

How can this be done?

Thanks


I just had to deal with the same question, and I solved it by creating some helper functions for FancyBox. The fb_resize(w,h) function resizes the fancybox-content div then calls $.fancybox.resize() to adjust for the modified content. The fb_close_any() and fb_resize_any(w,h) functions can be called from within any content, including an iFrame, to close or resize the fancybox.

function fb_resize(w, h) {
  if (w > 0 || h > 0) {
    if (w > 0) $('#fancybox-content').css({ width: w+"px"});
    if (h > 0) $('#fancybox-content').css({ height: h+"px"});
    $.fancybox.resize();
  }
}

function fb_close_any() {
  window.top.eval('$.fancybox.close()');
}

function fb_resize_any(w, h) {
  w = (w > 0) ? w : 0;
  h = (h > 0) ? h : 0;
  window.top.eval('fb_resize('+w+','+h+')');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜