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

后端 未结 3 1401
半阙折子戏
半阙折子戏 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:34

    Assuming you have only 1 IFRAME in the main window, from the Javascript of the IFRAME's document you can do something like:

    function getMySelf()
    {
        return (window.parent.document.getElementsByTagName("iframe"))[0];
    }
    
    var myself = getMySelf();
    myself.style.width = whateverWidth;
    myself.style.height = whateverHeight;
    

提交回复
热议问题