在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錯誤。
例子
opener.html
復制代碼 代碼如下:
<html>
<body>
<form name=form1>
<input type=text name=inpu >
<input type=button >
</form>
</body>
</html>
復制代碼 代碼如下:
<html>
<body>
<form name=form1>
<input type=text name=inpu >
<a class=under href=#>添加</a>
</form>
</body>
</html>
新聞熱點
疑難解答
圖片精選