框架頁面高度自動刷新的Javascript腳本
更新時間:2013年11月01日 17:29:10 作者:
框架頁面高度自動刷新,加載index.htm時候,每隔1秒鐘自動調(diào)用腳本刷新框架頁面代碼,具體實現(xiàn)如下,感興趣的朋友可以了解下
實現(xiàn)原理:加載index.htm時候,每隔1秒鐘自動調(diào)用腳本刷新框架頁面代碼
代碼優(yōu)點:只需要設(shè)置index.html框架頁面中的腳本,調(diào)用加載的子頁面中不需要設(shè)置任何代碼。
index.htm代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>首頁</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div style="float: left; width: 740px; height:auto; border: 1px #808080 Solid; margin: 5px 0px 5px 10px;overflow: hide">
<iframe name="ifr_obj" id="ifr_obj" src="這里嵌套其它頁面地址或者文件名" frameborder="0" width="100%" scrolling="no" title="框架頁面"></iframe>
</div>
</body>
<script language="javascript" type="text/javascript">
function initIframeHeight() {
try {
var iframe = document.getElementById("ifr_obj");
if (iframe != null) {
if (iframe.contentWindow.document.body != null) {
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}
}
}
catch (ex) {
alert("加載框架頁面高度時出錯"+ex.toString());
}
}
window.setInterval("initIframeHeight()", 1000);
</script>
</html>
代碼優(yōu)點:只需要設(shè)置index.html框架頁面中的腳本,調(diào)用加載的子頁面中不需要設(shè)置任何代碼。
index.htm代碼如下:
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>首頁</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div style="float: left; width: 740px; height:auto; border: 1px #808080 Solid; margin: 5px 0px 5px 10px;overflow: hide">
<iframe name="ifr_obj" id="ifr_obj" src="這里嵌套其它頁面地址或者文件名" frameborder="0" width="100%" scrolling="no" title="框架頁面"></iframe>
</div>
</body>
<script language="javascript" type="text/javascript">
function initIframeHeight() {
try {
var iframe = document.getElementById("ifr_obj");
if (iframe != null) {
if (iframe.contentWindow.document.body != null) {
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}
}
}
catch (ex) {
alert("加載框架頁面高度時出錯"+ex.toString());
}
}
window.setInterval("initIframeHeight()", 1000);
</script>
</html>
您可能感興趣的文章:
相關(guān)文章
JavaScript中變量聲明有var和沒var的區(qū)別示例介紹
在函數(shù)內(nèi)部,有var和沒var聲明的變量是不一樣的。有var聲明的是局部變量,沒var的,聲明的全局變量,所以可以借此向外暴露接口東東2014-09-09JavaScript 數(shù)據(jù)元素集合與數(shù)組的區(qū)別說明
我們在獲取一組頁面元素時常會用到getElementsByName()或是getElementsByTagName()方法。2010-05-05js實現(xiàn)rem自動匹配計算font-size的示例
本篇文章主要介紹了js實現(xiàn)rem自動匹配計算font-size的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11