广 告 位 置 |
|
|
 |
站 内 搜 索 |
|
|
 |
|
|
|
|
Iframe自适应加载网页的内容高度
来源:盛绿设计 等级:默认等级
发布于2006-10-25 00:31 被读41次 【字体:大 中 小】
|
|
摘要:这篇文章主要针对有一定html编程经验介绍了在静态页面进行页面之间调用自适应其加载的网页的方法。
1.htm 代码如下:
<html> <head> <meta http-equiv=’Content-Type’ content=’text/html; charset=gb2312’> <meta name=’author’ content=’吕海鹏//www.DeepTeach.com’> <title>iframe自适应加载的页面高度</title> </head> <body>
<!-- 加载网页 开始-->
<iframe src="2.htm" frameBorder="0" scrolling="no" width="100%" ></iframe>
<!-- 加载网页 结束-->
</body> </html> |
iframe调用页 2.htm 代码如下:
<html> <head> <meta http-equiv='Content-Type' content='text/html; charset=gb2312'> <meta name='author' content='吕海鹏//www.DeepTeach.com'> <title>iframe 自适应其加载的网页(多浏览器兼容)</title> <script language=javascript> function iframeAutoFit() { try { if(window!=parent) { var a = parent.document.getElementsByTagName("IFRAME"); for(var i=0; i<a.length; i++) //www.deepteach.com { 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; } } } } catch (ex) { alert("脚本无法跨域操作!"); } } if(document.attachEvent) window.attachEvent("onload", iframeAutoFit); else window.addEventListener(’load’, iframeAutoFit, false); </script> </head> <body> <!-- 在body内添加内容自动适应其加载的网页 开始--> <div style="width: 100%; height: 400; background-color: #99CCFF"> iframe 自适应其加载的网页(多浏览器兼容) </div> <!-- 在body内添加内容自动适应其加载的网页 结束--> </body> </html> | 重要提示:src=中填写的网页地址,一定要和本页面在同一个站点上,否则,脚本无法跨域操作!会抱错,拒绝 访问!
|
相关专题:暂无相关专题
上一篇:网页Flash播放代码的一个小技巧 下一篇:通通透透了解Cookies
|
共有评论 0 条 网友评分 查看全部
|
|
|