javascript showModalDialog,open取得父視窗的方法

來源:互聯網
上載者:User

通常使用window.open的方式開啟新視窗的話
要取得父視窗的控制項,可以用window.opener來取得父視窗
然而如果使用showModalDialog的話...卻無效
如果有需要的話,需要修改開啟的文法以及showModalDialog中的文法
開啟文法第2個參數請下self,範例如下
var rc=window.showModalDialog(strURL,self,sFeatures);
然後接著就是呼叫父視窗的文法
var pWindow=window.dialogArguments;
這樣就可以取得父視窗的window對象控制了。例如:
window.dialogArguments.document.getElementsByName("processId")[0].value;

js中 opener和parent的區別

opener即誰開啟我的,比如A頁面利用window.open彈出了B頁面視窗,那麼A頁面所在視窗就是B頁面的
opener,在B頁面通過opener對象可以訪問A頁面。
parent表示父視窗,比如一個A頁面利用iframe或frame調用B頁面,那麼A頁面所在視窗就是B頁面的
parent。
在JS中,window.opener只是對快顯視窗的母視窗的一個引用。比如:
a.html中,通過點擊按鈕等方式window.open出一個新的視窗b.html。那麼在b.html中,就可以通過
window.opener(省略寫為opener)來引用a.html,包括a.html的document等對象,操作a.html的內容。
假如這個引用失敗,那麼將返回null。所以在調用opener的對象前,要先判斷對象是否為null,否則會
出現“對象為空白或者不存在”的JS錯誤。 複製代碼 代碼如下:<html>
<body>
<form. name=form1>
<input type=text name=inpu >
<input type=button >
</form>
</body>
</html>

back2opener.html 複製代碼 代碼如下:<html>
<body>
<form. name=form1>
<input type=text name=inpu >
<a class=under href=# >添加</a>
</form>
</body>
</html>

window.opener 返回的是建立當前視窗的那個視窗的引用,比如點擊了a.htm上的一個連結而開啟了
b.htm,然後我們打算在b.htm上輸入一個值然後賦予a.htm上的一個id為“name”的textbox中,就可以
寫為:
window.opener.document.getElementById("name").value = "輸入的資料";

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.