完美iframe自适应宽度和高度(支持ie,ff)
2009-12-18 11:30
731 查看
在ie下能实现的功能,对照着FF下的方法与属性修改就行了。今天终于把这个问题彻底解决了,记录一下。
感谢http://www.cnblogs.com/Cheese_Ren/
js代码如下:
代码
//iframe高度自适应
function IFrameReSize(iframename) {
var pTar = document.getElementById(iframename);
if (pTar) { //ff
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
pTar.height = pTar.contentDocument.body.offsetHeight;
} //ie
else if (pTar.Document && pTar.Document.body.scrollHeight) {
pTar.height = pTar.Document.body.scrollHeight;
}
}
}
//iframe宽度自适应
function IFrameReSizeWidth(iframename) {
var pTar = document.getElementById(iframename);
if (pTar) { //ff
if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) {
pTar.width = pTar.contentDocument.body.offsetWidth;
} //ie
else if (pTar.Document && pTar.Document.body.scrollWidth) {
pTar.width = pTar.Document.body.scrollWidth;
}
}
}
使用方法如下:
<iframe src="Main.aspx" scrolling="no" frameborder="0" height="100%" id="mainFrame" width="100%" onload='IFrameReSize("mainFrame");IFrameReSizeWidth("mainFrame");'></iframe>
参考:
/article/4667321.html
感谢http://www.cnblogs.com/Cheese_Ren/
js代码如下:
代码
//iframe高度自适应
function IFrameReSize(iframename) {
var pTar = document.getElementById(iframename);
if (pTar) { //ff
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
pTar.height = pTar.contentDocument.body.offsetHeight;
} //ie
else if (pTar.Document && pTar.Document.body.scrollHeight) {
pTar.height = pTar.Document.body.scrollHeight;
}
}
}
//iframe宽度自适应
function IFrameReSizeWidth(iframename) {
var pTar = document.getElementById(iframename);
if (pTar) { //ff
if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) {
pTar.width = pTar.contentDocument.body.offsetWidth;
} //ie
else if (pTar.Document && pTar.Document.body.scrollWidth) {
pTar.width = pTar.Document.body.scrollWidth;
}
}
}
使用方法如下:
<iframe src="Main.aspx" scrolling="no" frameborder="0" height="100%" id="mainFrame" width="100%" onload='IFrameReSize("mainFrame");IFrameReSizeWidth("mainFrame");'></iframe>
参考:
/article/4667321.html
相关文章推荐
- js实现的非跨域的iframe高度自适应(完美兼容IE,FF,Opera)
- JQuery IFrame框架高度自适应(支持嵌套–兼容IE,ff,safafi,chrome)
- JQuery IFrame框架高度自适应(支持嵌套–兼容IE,ff,safafi,chrome)
- 为何firefox不支持insertRow和insertCell。我如何能让firefox显示和ie显示的效果一样?iframe实现高度自适应,兼容FF、Opera、Safari
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
- Iframe自适应高度_IE_FF下都可用
- iframe自适应高度(支持XHTML,支持FF)
- IE FF 兼容的IFRAME 自适应高度JS代码
- iframe高度自适应,兼容IE,FF
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
- iframe页面调用高度自适应方法代码,兼容IE,FF
- 同域及跨域下iframe高度自适应(兼容IE/FF/OP/Chrome)
- JQuery自适应IFrame高度(支持嵌套--兼容IE,ff,safafi,chrome)
- 真正的iframe高度自适应(兼容IE,FF,Opera)
- iframe高度自适应,兼容IE,FF
- JQuery自适应IFrame高度(支持嵌套 兼容IE,ff,safafi,chrome)
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
- iFrame自适应高度,支持IE及FireFox
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)