您的位置:首页 > Web前端 > JavaScript

JS_同域下的ifream自适应高度和设置注意等

2012-08-10 22:05 141 查看
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;
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: