實(shí)現(xiàn)原理:加載index.htm時(shí)候,每隔1秒鐘自動(dòng)調(diào)用腳本刷新框架頁(yè)面代碼
代碼優(yōu)點(diǎn):只需要設(shè)置index.html框架頁(yè)面中的腳本,調(diào)用加載的子頁(yè)面中不需要設(shè)置任何代碼。
index.htm代碼如下:
復(fù)制代碼 代碼如下:
<!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>首頁(yè)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<iframe src="這里嵌套其它頁(yè)面地址或者文件名" frameborder="0" scrolling="no" 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("加載框架頁(yè)面高度時(shí)出錯(cuò)"+ex.toString());
}
}
window.setInterval("initIframeHeight()", 1000);
</script>
</html>
新聞熱點(diǎn)
疑難解答
圖片精選