我想在我的页面上显示一个 fancybox,显示一个 iframe,其中包含具有动态高度的另一个域的源(因为在 iframe 中我将转到不同的页面或可能有一些动态内容)。我也可以访问其他域的代码。所以我可以使用 postMessage 将 iframe 源的高度发送到我的页面。但我似乎不知道如何通过代码更改 fancybox 的高度。
我尝试设置包含 iframe 的所有 div 的高度,包括 iframe 本身:
document.getElementById('fancybox-frame').height = parseInt(height);
document.getElementById('fancybox-content').height = parseInt(height);
document.getElementById('fancybox-outer').height = parseInt(height);
document.getElementById('fancybox-wrap').height = parseInt(height);
而且我知道我的高度完全正确,因为它在直接集成的 iframe 上完美运行。
有人有什么想法吗?
谢谢
编辑: 我也尝试过 $.fancybox.update() 但我不太确定如何实现:
$.fancybox({
'height': height
});
$.fancybox.update();
最佳答案
您是否尝试过内置的 $.fancybox.update()
方法? the documentation建议(在 API 方法下)此方法应该提供您正在寻找的功能。
关于javascript - 使用 jquery 设置 fancybox 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19876787/