0

i try to access an iFrame with the following code:

iframe = document.getElementById('typo3-contentIframe');
iframe.onload = function() {
    console.log(iframe);
}

This is my output in the browser console after 1 (!) request

How is this possible? First I have access on the iframe, but after that it is null.

What can I do, that I have permanent access to the iframe?

mplungjan
  • 134,906
  • 25
  • 152
  • 209
Minux
  • 1
  • Please show the HTML that contains the iframe. Also you cannot assign onload to an iframe that already has loaded and you cannot access the iframe content if not from same origin – mplungjan May 17 '20 at 12:14
  • I am afraid that the HTML with the iframe is very extensive. Its from the Typo3 Admin Menu. But you are right, my script is on a other server than the iframe, but I include on my script-Server in the htaccess - Header set Access-Control-Allow-Origin "*". Is this not enought? What else can I do? Thank you for your help! – Minux May 17 '20 at 12:34
  • It is not a CORS issue but an ORIGIN issue. Imagine the content of your iframe was a bank... – mplungjan May 17 '20 at 12:38
  • Oh ok, and there is nothing what i can do? The script I want to use to access the iframe must be on the same server as the iframe? – Minux May 17 '20 at 12:44
  • Yes, that is basically it. You can use a proxy on your server to get the other site and ajax it into your page – mplungjan May 17 '20 at 12:47

0 Answers0