標籤:javascript
執行個體008 關閉彈出的視窗時,重新整理父視窗執行個體說明關閉彈出的視窗時,同時重新整理父視窗,一般用來使父視窗擷取最新的資料。技術要點本執行個體主要應用window.open()語句開啟新視窗,並在新視窗中應用opener屬性,該屬性返回一個引用,用於指定開啟本視窗的視窗對象。文法:window.openerwindow.opener.方法window.opener.屬性功能:返回的是一個視窗對象。opener屬性與開啟該視窗的父視窗相聯絡,當訪問子視窗中opener屬性時,返回的是父視窗,通過該屬性,可以使用父視窗對象中的方法和屬性。reload()方法是用來重新整理指定視窗的。實現過程(1)要彈出的視窗,並且實現關閉重新整理父視窗的頁面new.html
<html><head><meta charset="utf-8" /><title>彈出的視窗</title><style type="text/css">body{background-image:url(new.jpg);background-repeat:no-repeat;}</style><script>function pp(){alert(window.opener);window.opener.location.reload();window.close();}</script></head><body><input type = "button" value = "關閉" onClick="pp();"/></body></html>(2)主視窗index.html
<html><head> <meta charset="utf-8" /> <script type="text/jscript" language="javascript">window.open("new.html","new","height=280,width=800,top=10,left=20,resizable=no, location=no",false); </script> <style type="text/css"> p{font-size:24px;color:#F00;} </style> </head> <body> <p>網站首頁</p> </body></html>註:style標籤的內容為css的知識,我們關注的是script標籤內的內容。這樣我們的這個執行個體就做好了。
JavaScript特效執行個體008-關閉彈出的視窗時,重新整理父視窗