標籤:style blog http java 使用 os strong for
1、window.parent 是iframe頁面調用父頁面對象
舉例: a.html
<html>
<head><title>A</title></head>
<body>
<form name="form1" id="form1">
<input type="text" name="username" id="username"/>
</form>
<iframe src="b.html" width=100%></iframe>
</body>
</html>
如果我們需要在b.html中要對a.html中的username文字框賦值(就如很多上傳功能,上傳功能頁在ifrmae中,上傳成功後把上傳後的路徑放入父頁面的文字框中),我們應該在b.html中寫:
<script type="text/javascript">
var _parentWin = window.parent;
_parentWin.form1.username.value = "xxxx";
</script>
Z-Blog的文章編輯頁面上傳功能就是這麼實現的。
2、window.opener 是 window.open 開啟的子頁面調用父頁面對象
opener:對開啟當前視窗的window對象的引用,如果當前視窗被使用者開啟,則它的值為null。
self代表自身視窗,opener代表開啟自身的那個視窗,比如視窗a.html開啟視窗b.html。如果靠window.open方法,則對於視窗b.html,self代表b.html自己,而opener代表視窗a.html。
舉例:a.html
<input type="text" name="username" id="username"/>
<a onclick="window.open(this.href,‘‘,‘resizable=yes,width=800,height=600,status‘); return false" href="b.html">B</a>
如果需要在b.html中對a.html中的表單元素賦值,我們應該在b.html中這麼寫
<a href="javascript:try{window.opener.document.getElementById(‘username‘).contentWindow.
frames[0].document.getElementsByTagName(‘body‘)[0].innerHTML+=‘xxx‘}catch(e){};window.close();">插入</a>
在後面用window.close關閉b.html。WindsPhoto 2.7.3 中在文章編輯頁面彈出新視窗(圖片列表)後,選擇插入已上傳圖片便是如此實現的。