调整iframe大小以适应其内容 [英] Resizing iframe to fit its content

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

问题描述


可能重复:

基于内容调整iframe大小

我有一个iframe,其中src是一个HTML文件,这个iframe放在usercontrol中:

I have an iframe where the src is an HTML file and this iframe is put inside usercontrol:

<iframe frameborder="0" src="CName.htm" align="left" width="730" height="1100" ></iframe>

我需要根据内容调整iframe的大小,以便根据hieght的高度设置高度HTML文件,我不需要使用滚动属性。
您有什么想法吗?

I need the iframe to resize according to the content so that it's height is set according to the hieght of the HTML file and I don't need to use scrolling attribute. Do you have any idea?

推荐答案

我使用了以下jQuery代码来执行此操作:

I've used the following jQuery code to do this:

$('#iframe_id').load(function () {
    $(this).height($(this).contents().height());
    $(this).width($(this).contents().width());
});

如果iframe内容是跨域的,我认为这不会起作用。

I don't think this will work if the iframe contents are cross-domain, though.

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

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