使两个iframe的高度与内容自适应,且相等
时间:2020-11-10 15:39:14|栏目:JavaScript代码|点击: 次
<div class="TxtBox">
<iframe frameborder="0" scrolling="no" name="news1" id="news1" onload="if(document.frames['news1'].document.body.scrollHeight>document.frames['news2'].document.body.scrollHeight) document.all.news1.height=document.frames['news1'].document.body.scrollHeight;if(document.frames['news1'].document.body.scrollHeight<=document.frames['news2'].document.body.scrollHeight) document.all.news1.height=document.frames['news2'].document.body.scrollHeight;" src="https://www.jb51.net" width="100%"></iframe>
</div>
<div class="TxtBox">
<iframe frameborder="0" scrolling="no" name="news2" id="news2" onload="if(document.frames['news1'].document.body.scrollHeight>document.frames['news2'].document.body.scrollHeight) document.all.news2.height=document.frames['news1'].document.body.scrollHeight;if(document.frames['news1'].document.body.scrollHeight<=document.frames['news2'].document.body.scrollHeight) document.all.news2.height=document.frames['news2'].document.body.scrollHeight;" src="https://www.jb51.net/index_1.htm" width="100%"></iframe>
</div>
jb51提醒啊,多浏览期兼容需要注意些地方,不要用document.all用兼容好的,
<iframe frameborder="0" scrolling="no" name="news1" id="news1" onload="if(document.frames['news1'].document.body.scrollHeight>document.frames['news2'].document.body.scrollHeight) document.all.news1.height=document.frames['news1'].document.body.scrollHeight;if(document.frames['news1'].document.body.scrollHeight<=document.frames['news2'].document.body.scrollHeight) document.all.news1.height=document.frames['news2'].document.body.scrollHeight;" src="https://www.jb51.net" width="100%"></iframe>
</div>
<div class="TxtBox">
<iframe frameborder="0" scrolling="no" name="news2" id="news2" onload="if(document.frames['news1'].document.body.scrollHeight>document.frames['news2'].document.body.scrollHeight) document.all.news2.height=document.frames['news1'].document.body.scrollHeight;if(document.frames['news1'].document.body.scrollHeight<=document.frames['news2'].document.body.scrollHeight) document.all.news2.height=document.frames['news2'].document.body.scrollHeight;" src="https://www.jb51.net/index_1.htm" width="100%"></iframe>
</div>
jb51提醒啊,多浏览期兼容需要注意些地方,不要用document.all用兼容好的,
上一篇:js实现旋转的星空效果
栏 目:JavaScript代码
下一篇:Javascript从数组中随机取出不同元素的两种方法
本文地址:http://www.codeinn.net/misctech/20993.html