最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Colorbox iframe resize - Stack Overflow

programmeradmin0浏览0评论

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);
        }

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.

Any assistance would be most appreciated.

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);
        }

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.

Any assistance would be most appreciated.

Share Improve this question edited Feb 22, 2012 at 12:28 dif 2,4936 gold badges38 silver badges51 bronze badges asked Feb 21, 2012 at 11:55 user1223248user1223248 411 gold badge1 silver badge3 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 17

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>

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)

Did you try resize() without any argument ? It should resize with its own auto-calculations. But you can also try

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

Check this link for more information.

发布评论

评论列表(0)

  1. 暂无评论