window.opener介紹
window.opener:
--> returns a reference to the window that created the window.
--> When opening a window with the window.open() method, you can use this property from the destination window to return details of the source (parent) window.
--> Coding Tip: window.opener.close() will close the source (parent) window.
簡言之, 此屬性用來控制快顯子視窗的父視窗能使用什麼屬性或方法
Window opener Property:
http://www.w3schools.com/jsref/prop_win_opener.asp
最後, 說一下另一種情況:
眾所周知JavaScript中:
var win = window.open(url,windowName,...); 的使用,
而win.opener則是指向父視窗的引用
然而,有種情況卻比較特別,
window.opener用法:
http://fecbob.pixnet.net/blog/post/39261033-window.opener%E7%94%A8%E6%B3%95
從這篇擷取重點如下,
e.g.
假如有兩個視窗window1和window2
按下列步驟執行:
var win = window.open(url,windowName,...);// (window1)
var win = window.open(url,windowName,...);//(window2)
其中先後這兩次打開的子視窗的windowName一樣
此時你會發現在window2中的win.opener卻不是指向window2的,卻是指向window1.
如果你想在子視窗關閉父視窗的話,就不正確了,因此可以修改上面的執行方法為:
var win = window.open(url,windowName,...);? (window1)
win.opener = window;
var win = window.open(url,windowName,...);? (window2)
win.opener = window;
只有這樣修改才OK
--> returns a reference to the window that created the window.
--> When opening a window with the window.open() method, you can use this property from the destination window to return details of the source (parent) window.
--> Coding Tip: window.opener.close() will close the source (parent) window.
簡言之, 此屬性用來控制快顯子視窗的父視窗能使用什麼屬性或方法
Window opener Property:
http://www.w3schools.com/jsref/prop_win_opener.asp
最後, 說一下另一種情況:
眾所周知JavaScript中:
var win = window.open(url,windowName,...); 的使用,
而win.opener則是指向父視窗的引用
然而,有種情況卻比較特別,
window.opener用法:
http://fecbob.pixnet.net/blog/post/39261033-window.opener%E7%94%A8%E6%B3%95
從這篇擷取重點如下,
e.g.
假如有兩個視窗window1和window2
按下列步驟執行:
var win = window.open(url,windowName,...);// (window1)
var win = window.open(url,windowName,...);//(window2)
其中先後這兩次打開的子視窗的windowName一樣
此時你會發現在window2中的win.opener卻不是指向window2的,卻是指向window1.
如果你想在子視窗關閉父視窗的話,就不正確了,因此可以修改上面的執行方法為:
var win = window.open(url,windowName,...);? (window1)
win.opener = window;
var win = window.open(url,windowName,...);? (window2)
win.opener = window;
只有這樣修改才OK
留言
張貼留言