NO.1: 创建一个无边框的ifream.

  <iframe src="ifream.html" frameborder="0" width="300" height="150"  id="myframe1">

NO.2:设置ifream的背景.

  在ifream.html里面写样式设置body的背景.

NO.3:使ifream的高度自适应.

  在ifream.html内定义一个高度为250的DIV.

    .main{background:#F00;height:200px}

    <div id="main" class="main">1</div>

  自己的页面内JS代码:

function addEvent(id,en,fu){
    if(id.addEventListener){
        id.addEventListener(en,fu,false);
        }else if(id.attachEvent){
        id.attachEvent("on"+en, fu);
        }
    }
var if1 = document.getElementById("myframe1");
if(if1.Document){
    addEvent(if1,"load",function(){
        if1.height = if1.Document.documentElement.scrollHeight;
        });
    }else if(if1.contentDocument){
    addEvent(if1,"load",function(){
        if1.height = if1.contentDocument.documentElement.scrollHeight;
        });
    }
posted on 2012-08-10 22:05  somesayss  阅读(653)  评论(0)    收藏  举报