iframe高度自适应谁会啊?在网上找了几个测试都不可以用,有没有哪位大虾给个案例,小弟在此万分感谢! :arrow:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
[code="java"]
典代码 iFrame 自适应高度,在IE/Firefox/Opera/Chrome通过测试。
[code="java"]
Javascript代码:
function iFrameHeight() { var ifm= document.getElementById("iframepage"); var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument; if(ifm != null && subWeb != null) { ifm.height = subWeb.body.scrollHeight; } }[/code]
参考!
[url]http://www.jb51.net/article/15780.htm[/url]
参考连接:
[url]http://www.cnblogs.com/_zjl/archive/2012/03/15/2397884.html[/url]
[code="html"]
[/code]
[code="javascript"]
//高度自适应
var iframe = document.getElementById("testIframe");
var iframeHeight = function() {
var hash = window.location.hash.slice(1), h;
if (hash && /height=/.test(hash)) {
h = hash.replace("height=", "");
iframe.height = h;
}
setTimeout(iframeHeight, 100);
};
iframeHeight();
[/code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">