Because of several iframes, XUL browser elements, and so forth, I have a number of window objects in my XULRunner application. I'm looking for the best way to find the window object that a specified node belongs to using JavaScript.
So, to be more specific, given node x, I need to find the specific window object that contains x.
+1 to your question, it was exactly what I was looking for and thanks for the hint given directly by answering yourself.
I Googled a bit and according to http://www.quirksmode.org/dom/w3c_html.html cross-browsers tables I think the right answer is:
function GetOwnerWindow(html_node)
{
/*
ownerDocument is cross-browser,
but defaultView works on all browsers except Opera/IE that use parentWinow
*/
return (html_node.ownerDocument.defaultView) ?
html_node.ownerDocument.defaultView :
html_node.ownerDocument.parentWindow;
}
Or maybe even better:
return html_node.ownerDocument.defaultView || html_node.ownerDocument.parentWindow;
Plz let me know your thoughts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With