一、window.parent 是iframe頁面調用父頁面對象javascript
舉例: a.htmlhtml
<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中寫:java
<script type=」text/javascript」> var _parentWin = window.parent; _parentWin.form1.username.value = 「xxxx」; </script>
二、window.opener 是 window.open 打開的子頁面調用父頁面對象post
opener:對打開當前窗口的window對象的引用,若是當前窗口被用戶打開,則它的值爲null。this
self表明自身窗口,opener表明打開自身的那個窗口,好比窗口a.html打開窗口b.html。若是靠window.open方法,則對於窗口b.html,self表明b.html本身,而opener表明窗口a.html。spa
舉例:a.htmlcode
<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中這麼寫orm
<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 中在文章編輯頁面彈出新窗口(圖片列表)後,選擇插入已上傳圖片即是如此實現的。htm