开发者

Resizing iframe to fit contents when the web page has a resize event

I have an iframe that hosts web pages from various websites. In the onload handler for the iframe I resize it to fit the contents using jQuery:

height = iframe.find('body').attr('scrollHeight') + 100

This works fine开发者_开发问答 for most websites. However there is a website that has a window.onresize event which reloads the page. So it gets in an endless loop reloading the page where it is resized and therefore reloads the page.

How can I kill the resize event? I have tried all the following in my onload handler but none seem to work:

$('#webpage').resize(function() { alert("resizing"); return false});    
iframe.resize(function() { alert("resizing"); return false});    
window.onresize=null    
window.onresize=function() { alert("resizing"); return false};


Unless there is some crazy solution I simply don't know, the best way to stop the endless loop is probably to count how many times the onload handler for your iframe has been called. If it's been more than 1? 2? 3? times, then don't resize it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜