Colorbox iframe调整大小 [英] Colorbox iframe resize

查看:174
本文介绍了Colorbox iframe调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了许多对类似问题的回答,但找不到任何有效的方法。我是javascript的新手,但是已经足够让我的结果显示在iframe中,但是当我尝试建议的代码时:

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:

$.colorbox({ ... url, iframe true, etc

onComplete : function() { 
        $.fn.colorbox.resize(innerHeight);
        }

无论页面的html内容是什么,窗口都会调整为150像素高。会打开搜索结果的大小,然后每次运行新搜索时都可以调用它,但是我发现的 colorbox.resize()都没有变化

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.

任何帮助将不胜感激。

推荐答案

如果要根据Iframe的内容进行大小调整,则要调整大小的代码应位于Iframe内容内部,因为据我认为,只有Iframe知道它包含的内容,而不是加载它的父窗口。 b $ b在您的iframe内容中放入此c

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

<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>

Iframe完全加载后,将执行此代码,并调整您的Colorbox窗口大小。 (确保仅当您为Parent和iframe使用相同的域时,此代码才有效)

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)

这篇关于Colorbox iframe调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆