You can do this also without knowing the idof the iframe in the parent window:window.frameElement.style.width = iframeContentWidth + 'px';window.frameElement.style.height = iframeContentHeight + 'px';在 MDNframeElement>.See frameElement at MDN.编辑万一 iframe 恰好位于具有固定大小和 overflow: hidden 的容器元素中,您可以执行以下操作:Just in case the iframe happens to be in a container element which has fixed size and overflow: hidden you can do something like this:function resizeIframe (iframeContentWidth, iframeContentHeight) { var container = window.frameElement.parentElement; if (container != parent.document.body) { container.style.width = iframeContentWidth + 'px'; container.style.height = iframeContentHeight + 'px'; } window.frameElement.style.width = iframeContentWidth + 'px'; window.frameElement.style.height = iframeContentHeight + 'px'; return;} 这篇关于iframe 是否有可能在没有主窗口帮助的情况下调整自身大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 07:30
查看更多