0

I have a HTML website that inside the iframe I have a <script> tag.

I can get the iframe by running:

iframe = document.getElementsByTagName("iframe") 

When I print iframe[0] I received:

<iframe id="576259869" src="https://..." frameborder="0" allow="autoplay; fullscreen" allowfullscreen="" class="sc-kVrTmx jfegoL" data-ready="true"></iframe>
#document
 <html lang="en">
 <head>...</head>
 <body>
 <div id="..">...</div>
 <script>...</script>
 </body>
 </html>
</iframe>

I tried to catch it like that:

iframe[0].getElementsByTagName("script")

But it gives me an empty arrary HTMLCollection [] although I can see the tag inside the iframe.

asked Aug 8, 2021 at 16:50
8
  • "the tag inside the iframe" – It isn't inside the iframe, it is inside the document which is inside the iframe. Commented Aug 8, 2021 at 16:52
  • @Quentin so I can I get it ? Commented Aug 8, 2021 at 16:54
  • See the duplicates Commented Aug 8, 2021 at 16:54
  • @Quentin okay, the second answer might help. When I run iframe[0].contentWindow.document it gives me the origin policy error Commented Aug 8, 2021 at 17:02
  • The second duplicate covers the cross-origin issue. Commented Aug 8, 2021 at 17:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.