javascript 颜色框 iframe 调整大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9377162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Colorbox iframe resize
提问by user1223248
I've looked at many of the responses to similar questions and I can't find anything that works. I'm new to javascript but have got far enough to get my results to show in an iframe, but when I try the suggested code:
我查看了许多对类似问题的回答,但找不到任何有效的方法。我是 javascript 新手,但已经足够让我的结果显示在 iframe 中,但是当我尝试建议的代码时:
$.colorbox({ ... url, iframe true, etc
onComplete : function() {
$.fn.colorbox.resize(innerHeight);
}
the window resizes to 150pixels high. regardless of what is in the html of the page. Ideally it would open to the search results size, and then I could call it each time a new search is run, but none of the variations of colorbox.resize()
that I have found reference to do anything. Nada.
窗口大小调整为 150 像素高。不管页面的 html 中有什么。理想情况下,它会根据搜索结果大小打开,然后我可以在每次运行新搜索时调用它,但是colorbox.resize()
我没有发现任何变体可以做任何事情。纳达。
Any assistance would be most appreciated.
任何帮助将不胜感激。
回答by Ghulam Ali
If you want to resize according to contents of Iframe then your code to resize should be inside the Iframe contents. Because as far as I think only the Iframe knows what contents it contains, not the parent window that loads it. In your Iframe Contents put this code in head section
如果您想根据 Iframe 的内容调整大小,那么您要调整大小的代码应该在 Iframe 内容内。因为据我所知,只有 Iframe 知道它包含哪些内容,而不是加载它的父窗口。在您的 Iframe 内容中,将此代码放在 head 部分
<script type="text/javascript">
function Resize_Box(){
var x = $('body').width();
var y = $('body').height();
parent.$.fn.colorbox.resize({
innerWidth: x,
innerHeight: y
});
}
$(document).ready(function(){
Resize_Box();
});
</script>
When Iframe is fully loaded this code will be executed and your Colorbox window will be resized. (Make sure this code only works when you are using same domain for Parent and Iframe)
当 Iframe 完全加载时,此代码将被执行,您的 Colorbox 窗口将被调整大小。(确保此代码仅在您为父级和 Iframe 使用相同域时才有效)