根据内容的高度在它调整iframe的高度 [英] Resize iframe height according to content height in it

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

问题描述

我打开我的博客网页在我的网站。问题是,我可以给宽度的iframe但高度应该是动态的,以便有在iframe没有滚动条,它看起来像一个单页...

I am opening my blog page in my website. The problem is I can give a width to an iframe but the height should be dynamic so that there is no scrollbar in the iframe, and it looks like a single page...

我尝试了各种JavaScript的code来计算内容的高度,但他们都给出的拒绝访问权限的错误,是没有用的。

I have tried various JavaScript code to calculate the height of the content but all of them give an access denied permission error and is of no use.

<iframe src="http://bagtheplanet.blogspot.com/" name="ifrm" id="ifrm" width="1024px" ></iframe>

我们可以使用Ajax使用PHP来计算高度或可能?

Can we use Ajax to calculate height or maybe using PHP?

推荐答案

要直接回答你的两个subquestions:不,你不能用Ajax做到这一点,也可以用PHP计算它

To directly answer your two subquestions: No, you cannot do this with Ajax, nor can you calculate it with PHP.

我在过去做的是使用来自iframe'd页的触发器,的window.onload (不 domready中,因为它可能需要一段时间的图像加载)到页面的身高传递给家长。

What I have done in the past is use a trigger from the iframe'd page in window.onload (NOT domready, as it can take a while for images to load) to pass the page's body height to the parent.

<body onload='parent.resizeIframe(document.body.scrollHeight)'>

然后 parent.resizeIframe 是这样的:

function resizeIframe(newHeight)
{
    document.getElementById('blogIframe').style.height = parseInt(newHeight,10) + 10 + 'px';
}

等瞧,你有一个强大的大小调整触发一旦页面完全没有讨厌的 contentdocument VS contentWindow 摆弄:)

当然,现在人们将看到您的IFRAME在默认的高度第一,但是这可以通过隐藏您的IFRAME起初,只是呈现出装载的形象很容易处理。然后,当 resizeIframe 功能踢,摆在那里两个额外的线路,将隐藏载入图像,并显示在iframe为人造阿贾克斯的样子。

Sure, now people will see your iframe at default height first, but this can be easily handled by hiding your iframe at first and just showing a 'loading' image. Then, when the resizeIframe function kicks in, put two extra lines in there that will hide the loading image, and show the iframe for that faux Ajax look.

当然,这从同一个域唯一的作品,所以你可能需要有一个代理PHP脚本嵌入这个东西,一旦你去那里,你还不如干脆直接嵌入您的博客RSS提要到您的网站PHP。

Of course, this only works from the same domain, so you may want to have a proxy PHP script to embed this stuff, and once you go there, you might as well just embed your blog's RSS feed directly into your site with PHP.

这篇关于根据内容的高度在它调整iframe的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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