OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Does window.document.querySelector have access to the shadowDOM?

  • Thread starter Thread starter 장유진
  • Start date Start date

장유진

Guest
I have code like this, which selects a specific meta tag from the document. What I'm expecting from this code is to select and fetch the first tag out of the many tags in the head.

This code has been working fine until now, but something happened to select the meta tag inside the iframe's shadowDOM instead. As far as I know, the iframe works independently and is not accessible, so why would I want to access it?

The querySelector is looking for the first element, so even if I had access to the iframe, wouldn't the element in the head be the first?

Code:
const getDisplayLocation = () => {
  return window.document.querySelector('meta[name="temp_role"]').content;
};

I suspect window.document is the reason this is happening, but I haven't found the exact cause.

<p>I have code like this, which selects a specific meta tag from the document. What I'm expecting from this code is to select and fetch the first tag out of the many tags in the head.</p>
<p>This code has been working fine until now, but something happened to select the meta tag inside the iframe's shadowDOM instead. As far as I know, the iframe works independently and is not accessible, so why would I want to access it?</p>
<p>The querySelector is looking for the first element, so even if I had access to the iframe, wouldn't the element in the head be the first?</p>
<pre class="lang-js prettyprint-override"><code>const getDisplayLocation = () => {
return window.document.querySelector('meta[name="temp_role"]').content;
};
</code></pre>
<p>I suspect window.document is the reason this is happening, but I haven't found the exact cause.</p>
 

Latest posts

J
Replies
0
Views
1
Jeff P Chacko
J
Top