0

I search a solution to check a Cross-Origin iframe content. The problem is, that the iframe load an iframe, and in this iframe is not always loading content. Because of the cross-origin, the iframe content can not be queried. However, it is possible that a blank page is loaded in the iframe. An additional problem is that the iframe has a fixed height and width. So if no content is loaded, then a white area will be displayed in this height and width.

With Javascript I get to the src of the second iframe.

document.getElementsByTagName("iframe")[0].contentDocument.getElementsByTagName("iframe")[0].src;

Unfortunately, I can not get any further. The check should take place via Javascript at the client side. A separate check on the getted url does not help, because the content in the iframe is automatically generated via many factors. Each call may deliver a different content. So with the getted url a check does not work. The visible content needs to be checked in the iframe. If the content is a blank page, then something else should be displayed instead of the iframe, or the iframe should be set to display:none or heigth:0px and width:0px. I have no access to the iframe source and content. How can you do something like that? Please solutions with pure Javascript preferred.

DISCLAIMER: There is not a "access iframe content" question. There is a "check iframe content" question, maybe without read the iframe HTML document content (disallowed by cross origin. I know.).

Malama
  • 145
  • 1
  • 8
  • you can't access cross origin iframe content for obvious security considerations - *except through co-operative means like `postMessage`, which would need to be added to the cross origin content, hence co-operative* – Bravo Oct 16 '19 at 11:05
  • my question was not a "manipulate iframe content". for this many answers: no. my question was: why can i check the *visible* iframe content. i have not found a duplicate question. once solution possible was to check the iframe content via screenshot and read the pixel colors. or other solutions for *visible* iframe content. show me now a duplicate question, please. and than set my question as an duplicate. or show me a solution with postMessage. Please. – Malama Oct 16 '19 at 11:51
  • `why can i check the visible iframe content` - because you can't access cross origin iframe content, doesn't matter if you want to manipulate it or just see if it exists ... it's cross origin, and therefore inaccessible due to obvious security considerations – Bravo Oct 16 '19 at 11:54
  • nothing *access*. only *check*. please note. *check* means not only get iframe document content. There is no duplicate question. realized it. – Malama Oct 16 '19 at 12:36
  • `check means not only get iframe document content` huh? what do you want to check. please be specific - you have iframe within iframe ... so, which one is cross origin, and which one do you want to "check" (i.e. determine if it has content I guess is what you mean) – Bravo Oct 16 '19 at 12:40
  • `determine if it has content I guess is what you mean`. it's only near by my question. i have given a hint with "check pixels" with screenshot, but by that i have not found a solution. screenshot-tools (canvas) don't shot images. is only a image in the iframe, than is the screenshot blank. but i don't know if screenshot tools shot iframe content. Please remove the forwarding to another question. there have not a answer. I have no idea was all is possible to "check" a iframe has only a white page (no content). – Malama Oct 18 '19 at 11:45

0 Answers0