can an cross-domain iframe detect a browser's actual viewport dimensions?

浪子不回头ぞ 提交于 2019-12-09 22:10:22

问题


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.



来源:https://stackoverflow.com/questions/7350734/can-an-cross-domain-iframe-detect-a-browsers-actual-viewport-dimensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!