javascript 刷新框架

字號:


    其中framedemo.html由上下兩個頁面組成,代碼如下:
    以下是引用片段:
    < !doctype html public -//w3c//dtd html 4.0 transitional//en>
    < html>
    < head>
    < title> framedemo < /title>
    < /head>
    < frameset rows=50%,50%>
    < frame name=top src=top.html>
    < frame name=button src=button.html>
    < /frameset>
    < /html>
    現(xiàn)在假設(shè)top.html即上面地頁面有一個button來實(shí)現(xiàn)對下面頁面地刷新,可以用以下七種語句,哪個好用自己看著辦了.
    語句1. window.parent.frames[1].location.reload();
    語句2. window.parent.frames.bottom.location.reload();
    語句3. window.parent.frames[bottom].location.reload();
    語句4. window.parent.frames.item(1).location.reload();
    語句5. window.parent.frames.item('bottom').location.reload();
    語句6. window.parent.bottom.location.reload();
    語句7. window.parent['bottom'].location.reload();
    語句8. javascript:window.parent.location.reload();/刷新整個框架
    解釋一下:
    1.window指代地是當(dāng)前頁面,例如對于此例它指地是top.html頁面.
    2.parent指地是當(dāng)前頁面地父頁面,也就是包含它地框架頁面.例如對于此例它指地是framedemo.html.
    3.frames是window對象,是一個數(shù)組.代表著該框架內(nèi)所有子頁面.
    4.item是方法.返回?cái)?shù)組里面地元素.
    5.如果子頁面也是個框架頁面,里面還是其它地子頁面,那么上面地有些方法可能不行.top.html源代碼;(頁面上有七個按鈕,功能都是刷新下面地框架頁面)
    以下是引用片段:
    < !doctype html public -//w3c//dtd html 4.0 transitional//en>
    < html>
    < head>
    < /head>
    < body>
    < input type=button value=刷新1 onclick=window.parent.frames[1].location.reload()>< br>
    < input type=button value=刷新2 onclick=window.parent.frames.bottom.location.reload()>< br>
    < input type=button value=刷新3 onclick=window.parent.frames['bottom'].location.reload()>< br>
    < input type=button value=刷新4 onclick=window.parent.frames.item(1).location.reload()><br>
    < input type=button value=刷新5 onclick=window.parent.frames.item('bottom').location.reload()> br>
    < input type=button value=刷新6 onclick=window.parent.bottom.location.reload()>< br>
    < input type=button value=刷新7 onclick=window.parent['bottom'].location.reload()>< br>
    < /body>
    < /html>
    下面是bottom.html頁面源代碼,為了證明下方頁面地確被刷新了,在裝載完頁面彈出一個對話框.
    以下是引用片段:
    < !doctype html public -//w3c//dtd html 4.0 transitional//en>
    < html>
    < head>
    < /head>
    < body onload=alert('我被加載了!')>
    < h1>this is the content in button.html.< /h1>
    < /body>
    < /html>