I have 2 functions like below:
In popup window:
function caller(){
window.opener.myfunc($('.TestDiv'));开发者_运维技巧
}
In opener:
function myfunc(element){
alert(element.parents('html').html());
}
The above gives me access to the html root element within myfunc.
How do I get access to the window or document object from the passed in element?
Note: it must be from the passed in element as this may be coming from a different context to that in which myfunc is running.
You can obtain the document node that contains the selected element with the ownerDocument
property of the element node.
function myfunc(element) {
element[0].ownerDocument;
}
[0]
gets the native DOM element; ownerDocument
gets the ancestor document node.
精彩评论