I have a javascript code like this
var element = $("elementId");
I got the reference to the element (which is a div).
Now I need to get the reference to the window in which this div element resides. But the problem is, here the $ is passed from a different window. So now the element resides in a different window.
How to get reference to that window object which contains this div element? Pls Help.
Opening Browser Windows using JavaScript A new browser window can be opened from a JavaScript script using the open() method of the window object. The syntax for opening a new window is as follows: newWindowObj = window.
The window object is not part of the DOM. It is a host object implemented as the "global object" to complete an ECMAScript implementation. It has its own standard which is available from the W3C.
The window object is the topmost object of DOM hierarchy. It represents a browser window or frame that displays the contents of the webpage. Whenever a window appears on the screen to display the contents of document, the window object is created.
Get a reference to the DOM node, use the ownerDocument
property to get a reference to the document, then read its defaultView
property (parentWindow
for IE8-) to get a reference to the window:
var $element = $('#elementId'); var element = $element[0]; // Assume that element exists, otherwise an error will be thrown at the next line var doc = element.ownerDocument; var win = doc.defaultView || doc.parentWindow;
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