QuerySelector for Web Elements Inside iframe QuerySelector for Web Elements Inside iframe javascript javascript

QuerySelector for Web Elements Inside iframe


simple es6 adapted from h3manth:

document.querySelectorAll('iframe').forEach( item =>    console.log(item.contentWindow.document.body.querySelectorAll('a')))


if the original page's url isn't at the same domain with the iframe content, the javascript will treat the iframe as a black box, meaning it will not see anything inside it.


You can do this:document.querySelector("iframe").contentWindow.document.querySelector("button")https://m.youtube.com/watch?v=-mNp3-UX9Qc