How do I attach event to popup parent's parent?
I want to attach an event to popup parent's parent.
Hierarchy is like this:-
Form1(master page) containing iframe opens Form2(without master page) opens a popup.
I want to identify Form1 in开发者_如何学运维 popup opened by Form2 through Javascript.How do I do it?
It works only for Form2.
window.opener.document.attachEvent("onclick",setfocus);
Only if all are on the same hostname, protocol, and port number, and if the windows have not been closed:
// if you're opening Form2 from outside the iframe
window.opener.opener.document.attachEvent("onclick",setfocus);
// if you're opening Form2 from inside the iframe
window.opener.opener.parent.document.attachEvent("onclick",setfocus);
Note that attachEvent
is IE/Opera only, so if you expect this to work cross-browser, consider using addEventListener
for those other browsers.
I would also seriously reconsider opening numerous pop-up windows, opening pop-ups from those pop-ups, etc. For at least publicly accessible web applications, pop-up blockers would be a big enough problem alone.
It worked for me
window.top.opener.window.top.document.getElementById("contentIFrame").document.attachEvent("onclick",setfocus);
精彩评论