Posted on 2005-06-16 22:40
FlyPig Lin 閱讀(328)
評論(0) 編輯 收藏 所屬分類:
腳本
今天做了一個例子,是在一個框架頁里面寫另外兩個框架頁的內容,框架頁是這樣的:
frame.html:
<frameset?rows="15%,*"?cols="*"?framespacing="0"?frameborder="1"?id="out">
??<frame?src="top.html"?name="topFrame"?scrolling="no"?frameborder="1">
??<frameset?rows="*"?cols="20%,*"?framespacing="0"?frameborder="1"?id="in">
????<frame?src="left.html"?name="leftFrame"?scrolling="no"?>
????<frame?src="right.html"?name="rightFrame"?scrolling="no"?>
??frameset>
frameset>
?
其中top.html內容是:
<html>
??<head>tophead>
??<body?onLoad="alert('top?load?finish');">
??<script>


????function?writeFrame(frameName,content)
{?

??????if(parent.frames[frameName].document?!=?null)
{

????????if(parent.frames[frameName].document.body?!=?null)
{
??????????parent.frames[frameName].document.body.innerHTML?=?content;

????????}else
{
??????????window.setTimeout("writeFrame('"+frameName+"','"+content+"')",1000);
????????}

??????}else
{?
????????window.setTimeout("writeFrame('"+frameName+"','"+content+"')",1000);
??????}
?????}

?????

?????function?writeFrameDirect(frameName,content)
{
????????if(parent.frames[frameName].document?!=?null)
????????????if(parent.frames[frameName].document.body?!=?null)
????????????????parent.frames[frameName].document.body.innerHTML?=?content;
?????}


?????function?a()
{
????????writeFrame('leftFrame','top?write?left');?
????????writeFrame('rightFrame','top?write?right');?
?????}


?????function?b()
{
????????writeFrameDirect('leftFrame','top?write?left');?
????????writeFrameDirect('rightFrame','top?write?right');?
?????}

?????a();
?????//b();
??script>

??body>
html>

left.html內容是:
<html>
??<head>head>
??<body?onLoad="alert('left?load?finish');">
??body>
html>
?
right.html內容是:
<html>
??<head>head>
??<body?onLoad="alert('right?load?finish');">
??body>
html>
?
雖然明明框架頁onLoad的時候可以看出順序是:left,right,top.可是在top里面如果調用方法b()而不調用方法a(),那從top往left和right寫東西都是不起作用的.很奇怪哪.今天做一個菜單就是遇到這個問題.我要從top往left寫二級菜單的內容,可是調用b()卻寫不成,還好寶玉教了我writeFrame的方法.用setTimeout定時去查left或right加載完畢沒,完畢后才寫.非常感謝他的幫助.