0

I want to place the string inside the iframe from _top to _blank

Example :

My Domain : example.com

Data coming from iframe domain : example.net

String inside iframe

<a href="https://www.example.com" target="_top">foo</a><br />
<a href="https://www.example.net" target="_top">bar</a>

My try :

const frame = document.querySelectorAll('a[target="_top"]').forEach(el => el.target = '_blank');

My code working fine for replacing string outside the iframe but it not replacing the string inside the iframe.

Sted
  • 111
  • 6
  • 1
    because the content in an iframe is not part of the parent. If the iframe is in another domain there is nothing you can do to access it because of the same origin policy. If it is the same domain, you would have to access the content of the iframe and execute the same type of code on its DOM. – epascarello Sep 01 '22 at 16:52
  • It coming from `async` but not protected by sandbox – Sted Sep 01 '22 at 16:55
  • So if it is same domain, you need to access the content https://stackoverflow.com/questions/926916/how-to-get-the-bodys-content-of-an-iframe-in-javascript – epascarello Sep 01 '22 at 16:57
  • No mate. it not a same domain. i am getting data from different domain. So, no way to change iframe data? – Sted Sep 01 '22 at 17:06
  • 1
    No. [Same Origin Policy](https://en.wikipedia.org/wiki/Same-origin_policy) prevents you from touching content from another domain. – epascarello Sep 01 '22 at 17:14
  • Oh look, this question ***again*** – Rory McCrossan Sep 01 '22 at 18:33
  • Does this answer your question? [How can I access the contents of an iframe with JavaScript/jQuery?](https://stackoverflow.com/questions/364952/how-can-i-access-the-contents-of-an-iframe-with-javascript-jquery) – starball Sep 02 '22 at 03:53

0 Answers0