简体   繁体   中英

How can I resize a cross-domain iFrame that I do not have control over

There's a plethora of articles and questions on how to resize iFrames to fit the inner content for URL's that aren't cross-domain, or that are cross-domain but that are under the developers control.

But I cannot find how to resize an iFrame for which I have zero control over, and thus can't postMessage back to the parent.

Is this possible?

ie Imagine my site mysite.com is trying to iFrame CNN.com. How could I resize the CNN iFrame so that the entire contents of the iFrame displays, without needing to scroll through the CNN iFrame.

Edit

Since the iFrame is cross-domain, the simple solution of reading the content of the iFrame and re-sizing it based on the content height cannot work, due to security restrictions. For example, Chrome gives me this exception when trying to read the content of an iFrame on a different domain:

Uncaught SecurityError: Failed to read the 'contentDocument' property from > 'HTMLIFrameElement': Blocked a frame with origin " http://dev " from accessing a frame with origin " http://cnn.com ". Protocols, domains, and ports must match.

Due to this, a common solution is to make the iFramed content communicate with the hosting page, as seen here . However, since the URL in my case, CNN.com, is completely 3rd party and out of my control, I cannot follow the cross-domain workaround.

Based on the comments I received, it seems safe to say that it is impossible to re-size a cross-domain iFrame from the client/browser side.

Perhaps some complex server-side algorithm could request the page and attempt to give hints about the size, but nothing can be done on the client-side.

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