请教一下大家,如何让iframe自适应高度啊,我用css+div布的局,放在div里面的
3个回答
展开全部
javascript:
function dyniframesize(down) {
var pTar = null;
if (document.getElementById) {
pTar = document.getElementById(down);
}
else {
eval('pTar = ' + down + ';');
}
if (pTar && !window.opera) {
//begin resizing iframe
pTar.style.display = "block"
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
//ns6 syntax
pTar.height = pTar.contentDocument.body.offsetHeight + 50;
pTar.width = pTar.contentDocument.body.scrollWidth + 50;
}
else if (pTar.Document && pTar.Document.body.scrollHeight) {
//ie5+ syntax
pTar.height = pTar.Document.body.scrollHeight + 50;
pTar.width = pTar.Document.body.scrollWidth + 50;
}
}
//ifm.document.createStyleSheet("style/Common.css");
}
html:
<div id="showpage">
<iframe src="" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" id="ifm"
name="ifm" onload="javascript:dyniframesize('ifm');" width="100%"></iframe>
</div>
这样,不管引入的页面高度是多少,都可以自适应高度和宽度
function dyniframesize(down) {
var pTar = null;
if (document.getElementById) {
pTar = document.getElementById(down);
}
else {
eval('pTar = ' + down + ';');
}
if (pTar && !window.opera) {
//begin resizing iframe
pTar.style.display = "block"
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
//ns6 syntax
pTar.height = pTar.contentDocument.body.offsetHeight + 50;
pTar.width = pTar.contentDocument.body.scrollWidth + 50;
}
else if (pTar.Document && pTar.Document.body.scrollHeight) {
//ie5+ syntax
pTar.height = pTar.Document.body.scrollHeight + 50;
pTar.width = pTar.Document.body.scrollWidth + 50;
}
}
//ifm.document.createStyleSheet("style/Common.css");
}
html:
<div id="showpage">
<iframe src="" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" id="ifm"
name="ifm" onload="javascript:dyniframesize('ifm');" width="100%"></iframe>
</div>
这样,不管引入的页面高度是多少,都可以自适应高度和宽度
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询