|
查看: 1233|回复: 1
|
关于 IFRAME AutoResize
[复制链接]
|
|
|
- function iframeHeight(){ var frame = document.getElementById("main_content"); var newHeight = (frame.contentWindow || frame.contentDocument).document.body.scrollHeight; frame.height = newHeight;
复制代码
我用 javaScript 让 iframe auto resize with the content
In IE work fine...
but Chrome and FireFox..iframe's height can only increase, cannot decrease..各位大大请解惑。。 |
|
|
|
|
|
|
|
|
|
|
发表于 3-5-2010 02:32 AM
|
显示全部楼层
本帖最后由 JR86 于 3-5-2010 02:34 AM 编辑
請善用Google
or
把以下的程式碼丟到你的iframe裡面去吧!!
- function iframeAutoFit() {
- try {
- if(window!=parent) {
- var a = parent.document.getElementsByTagName("iframe");
- for(var i=0; i<a.length; i++) {
- if(a[i].contentWindow==window) {
- var h = document.body.scrollHeight;
- if(document.all) {h += 4;}
- if(window.opera) {h += 1;}
- a[i].style.height = h;
- }
- }
- }
- }
- }
- if(document.attachEvent) window.attachEvent("onload", iframeAutoFit);
- else window.addEventListener('load', iframeAutoFit, false);
复制代码 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|