简体   繁体   中英

How do I access the raw DOM of a cross-domain iframe?

I am trying to access the iframe DOM elements through a Chrome browser extension with something like document.querySelector("iframe").contentWindow.document The iframe's source is cross-domain. I'm getting a permission error, which Google tells me is because browsers specifically prohibit this.

However, I do have access to the raw DOM on my side from the inspector tool. If I run the same command in the console after inspecting element, I'm able to access the exact inner-HTML element I need with no permission error using the same exact command. I think this is because I'm looking at the DOM rather than trying to grab it from the source, which is what I need, just inside the chrome extension instead and not the chrome console. Is it possible to simply read the DOM of an inner-HTML element in an off-origin iframe? Even if it's not through the chrome extension?

At this point I'm thinking I'd have to edit the chrome browser itself. Please help.

You can not do this on cross-domain iframes due to security restrictions in the browser. You only option is to get the other site to enable CORS for your site

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM