is it possible that iframe resize itself without help from main window?

后端 未结 3 1398
半阙折子戏
半阙折子戏 2020-12-03 12:00

Both main window and iframe are on the same domain, but what I want to achieve is to resize iframe to fit its contents using js only within that iframe.

I also do no

3条回答
  •  佛祖请我去吃肉
    2020-12-03 12:29

    For same-origin content like yours, yes you can.

    To borrow from Gary's answer on the above question:

    In the iframe, window.parent refers to the global object of the parent document, not the document object itself. I believe you would need to use parent.document.getElementById

    Try accessing the iframe using parent.document, and see if this solves your issue.

提交回复
热议问题