欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js中opener與parent的區(qū)別詳細(xì)解析

 更新時(shí)間:2014年01月14日 10:00:25   作者:  
本篇文章主要是對(duì)js中opener與parent的區(qū)別進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助

opener即誰打開我的,比如A頁(yè)面利用window.open彈出了B頁(yè)面窗口,那么A頁(yè)面所在窗口就是B頁(yè)面的opener,在B頁(yè)面通過opener對(duì)象可以訪問A頁(yè)面。

parent表示父窗口,比如一個(gè)A頁(yè)面利用iframe或frame調(diào)用B頁(yè)面,那么A頁(yè)面所在窗口就是B頁(yè)面的parent。在JS中,window.opener只是對(duì)彈出窗口的母窗口的一個(gè)引用。比如:a.html中,通過點(diǎn)擊按鈕等方式window.open出一個(gè)新的窗口b.html。那么在b.html中,就可以通過window.opener(省略寫為opener)來引用a.html,包括a.html的document等對(duì)象,操作a.html的內(nèi)容。

假如這個(gè)引用失敗,那么將返回null。所以在調(diào)用opener的對(duì)象前,要先判斷對(duì)象是否為null,否則會(huì)出現(xiàn)“對(duì)象為空或者不存在”的JS錯(cuò)誤。

示例:
aa.html

復(fù)制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
</head>
<body>
<span id="name"></span>
<input type="button" " value="彈窗" onclick="window.open('bb.html')" />
</body>
</html

bb.html
復(fù)制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>無標(biāo)題文檔</title>
 </head>
 <body>
 <input type="text"  id="inputValue"/>
 <input type="button"  value="添加" onclick="window.opener.document.getElementById('name').innerHTML=inputValue.value"/>
 </body>
 </html>

window.opener 返回的是創(chuàng)建當(dāng)前窗口的那個(gè)窗口的引用,比如點(diǎn)擊了aa.htm上的一個(gè)鏈接而打開了bb.htm,然后我們打算在bb.htm上輸入一個(gè)值然后賦予aa.htm上的一個(gè)id為“name”的textbox中,就可以

寫為:
window.opener.document.getElementById("name").value = "輸入的數(shù)據(jù)";
window.opener.document.getElementById("name").innerHTML= "輸入的數(shù)據(jù)";

相關(guān)文章

最新評(píng)論