0

Is it possible to get iframe id within cross-origin iframe?

The html of iframe:

<iframe height="100%" width="100%" scrolling="yes" allowtransparency="true" id="vfFrameId_1544771685610" name="vfFrameId_1544771685610" allowfullscreen="true" force-aloha-page_aloha-page="" allow="geolocation *; microphone *; camera *"></iframe>

I tried:

  • window.frameElement, it returns null. So I can't use window.frameElement.id to get the id.

Is there any other solution?

zhm
  • 3,513
  • 3
  • 34
  • 55
  • https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy – Teemu Dec 14 '18 at 07:37
  • The only way is to use `window.postMessage` in iframe, and handle the message in page, get the frame id, then post it back? – zhm Dec 14 '18 at 09:40
  • If you've control over the cross-origin iframe, then post-messaging is probably the best [choice](https://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy). If you haven't control over the cross-origin iframe, then there's nothing you can do. The question is, what would you do with the id, you can't get the id without a reference to the iframe, and when you have it, getting its id is more or less useless ..? – Teemu Dec 14 '18 at 09:43

0 Answers0