<div>
<iframe id="myframe" marginHeight=0 marginWidth=0 frameBorder=0 src="innerframe.html" onload="IFrameResize()"></iframe>
</div>
在Chrome中不行,其他浏览器都可以!
function IFrameResize()
{
var iframe = document.getElementById("myframe");
var iframeDocument = null;
//safari和chrome都是webkit内核的浏览器,但是webkit可以,chrome不可以
if (iframe.contentDocument)
{
//ie 8,ff,opera,safari
iframeDocument = iframe.contentDocument;
}
else if (iframe.contentWindow)
{
// for IE, 6 and 7:
iframeDocument = iframe.contentWindow.document;
}
if (!!iframeDocument) {
iframe.width=iframeDocument.documentElement.scrollWidth+"px";
iframe.height=iframeDocument.documentElement.scrollHeight+"px";
} else {
alert("this browser doesn't seem to support the iframe document object");
}
}