how to detect iframe resize?

前端 未结 3 1200
难免孤独
难免孤独 2021-01-26 05:06

i have a page with a function to resize the height of iframe in this page as a height of content of iframe but whene the iframe has a toggle action the height change and the fun

3条回答
  •  执念已碎
    2021-01-26 05:42

    Do both the parent document and the iframe have the same origin? If so, it is easier.

    If not, you will need a workaround, that has been already discussed here in Stack Overflow.

    It consists of including another iframe inside the iframe, that would point to a special url on the same domain as the top document. This way, the top document and the bottom-most iframe can communicate through JavaScript (since they have both the same origin). This is a production solution I use myself. Some big sites use it, Facebook is known to use (or to have used?) this.

提交回复
热议问题