Resizing an iframe based on content

后端 未结 21 2480
南方客
南方客 2020-11-21 07:40

I am working on an iGoogle-like application. Content from other applications (on other domains) is shown using iframes.

How do I resize the iframes to fit the heigh

21条回答
  •  花落未央
    2020-11-21 08:09

    Here's a jQuery approach that adds the info in json via the src attribute of the iframe. Here's a demo, resize and scroll this window.. the resulting url with json looks like this... http://fiddle.jshell.net/zippyskippy/RJN3G/show/#{docHeight:5124,windowHeight:1019,scrollHeight:571}#

    Here's the source code fiddle http://jsfiddle.net/zippyskippy/RJN3G/

    function updateLocation(){
    
        var loc = window.location.href;
        window.location.href = loc.replace(/#{.*}#/,"") 
            + "#{docHeight:"+$(document).height() 
            + ",windowHeight:"+$(window).height()
            + ",scrollHeight:"+$(window).scrollTop()
            +"}#";
    
    };
    
    //setInterval(updateLocation,500);
    
    $(window).resize(updateLocation);
    $(window).scroll(updateLocation);
    

提交回复
热议问题