search

Home  >  Q&A  >  body text

How to get the innerHTML of an iframe using JavaScript

I want to get innerHTML from the web page. It uses iframe within the body content of the page html document.

This is the code I'm using but nothing seems to be happening. I also know they must be some problem in the code I have here and that's why it's not working properly.

document.querySelectorAll('"body > iframe"')[0].innerHTML; I've tried this so far and I'm looking online to see if I can somehow make it work.

This is the html portion of the code extracted manually from the browser debugger tool.

<body><div id="__next"><div id="main" class="jsx-834240835 desktop-container"><div class="jsx-1905932170 header-container white "><div class="jsx-1905932170 header-content"><div class="jsx-1905932170 hamburger-wrapper"><a href="https://www.tiktok.com/en "><a title="TikTok" class="jsx-3359950850 logo-link">/div><iframe src="https://www.tiktok.com/creator#/upload?lang=en /" style="height: 650px; border-style: none; width: 100%; margin-bottom: -6px;"></iframe><div style="visibility: hidden; position: absolute; bottom : 0px; left: 0px; right: 0px; height: 356px; z-index: -1;"></div><div id="creator-center-footer"><div class=" jsx-3176438893 footer-container"><footer class="jsx-3176438893 footer-content-wrapper"><div class="jsx-3176438893 tiktok-logo"><div class="jsx-1929089525 logo-container jsx-997609344"><img src="https://lf16-tiktok-web.ttwstatic.com/obj/tiktok-web/tiktok/web/node/_next/static/images/logo-7328701c910ebbccb5670085d243fc12 .svg" title="TikTok" class="jsx-1929089525 logo-icon"><img src="https://lf16-tiktok-web.ttwstatic.com/obj/tiktok-web/tiktok/web/ node/_next/static/images/logotext-9b4d14640f93065ec36dab71c806e135.svg" title="TikTok" class="jsx-1929089525 logo-text"></div><strong

Broken part of the html here so you can see more of it better.

`<iframe src="https:

I tried adding the iframe portion of the html element to the javascript code above, but it didn't seem to do anything. I'm sure I'm doing something wrong and may need to make more adjustments to the code.

P粉358281574P粉358281574276 days ago403

reply all(1)I'll reply

  • P粉659518294

    P粉6595182942024-02-27 00:30:05

    (document.getElementById('YOUR ID').contentDocument).body;

    reply
    0
  • Cancelreply