iframe 如何让它展现内容自适应高度

时间:2022-05-07 05:45:19

引用:

 <iframe id="ifm1" runat="server" src="/comment/page1?id=@productId" width="100%" height="100%"  frameborder="0" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="no" ></iframe>

js:

   function reinitIframe() {
var iframe = document.getElementById("ifm1");
try {
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
} catch (ex) { }
}