can an cross-domain iframe detect a browser's

2020-07-25 10:09发布

问题:

I have an iframe loaded inside a parent page - the iframe and parent page are on different domains.

Can my iframed site detect the actual browser dimensions?

回答1:

You can use the web API window.postMessage method too. It safely enables cross origin communication.

https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage



回答2:

The simple answer, is no. It cannot. Unless by some means the parent window can dynamically send data to the object inside the iframe...

However if the content inside the iframe was all made in %'s so that it would scale nicely (similar to a fluid web page layout), this could help?

What is it that you are directly trying to achive?



回答3:

I ended up using the excellent postMessage plugin from Ben Alman

http://benalman.com/projects/jquery-postmessage-plugin/

this allows for cross domain communication where you have control over both domains.