I need to know if the document element is the ROOT node of the page. For example:
<html> <-- ROOT Node
<head></head>
<body>
<iframe>
<html>...</html> <-- other document
</iframe>
<iframe>
<html>...</html> <-- other document
</iframe>
</body>
</html>
Javascript that is executed in iframe 1 or 2 should know if their document node is the root node.
Hope you can help me.
getRootNode() method. The getRootNode() method returns the node object's root node, it optionally also includes the shadow root if it is available. Composed: A Boolean that indicates if the shadow root should be returned (false), or a root node beyond shadow root (true).
In your example, rootNode is the HTML element from which to start recursively searching the hierarchical DOM tree (which is how the web page is represented in JavaScript) for elements with class name cn . This allows the caller of your function to specify from where they want to search for elements with class name cn .
documentElement returns the Element that is the root element of the document (for example, the <html> element for HTML documents).
You should be able to do this with top
:
if (window.top.document === window.document) {
// we're in the outermost window
}
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