简体   繁体   English

如何使用 javascript 从内部更改父 iframe 大小?

[英]how can i change the parent iframe size from inside with javascript?

we have a ReactJs code that will run as an iframe in a website the problem is that we have lots of clients that set iframe height 700px as default and we can not tell all of them to change it and we don't have access to the iframes.我们有一个 ReactJs 代码,它将在网站中作为 iframe 运行,问题是我们有很多客户端将 iframe 高度设置为 700px 作为默认值,我们不能告诉他们所有人都更改它,我们也无法访问iframe。 and this will make our project scrollable.这将使我们的项目可滚动。 we want to make it full size without scroll from inside.我们希望在没有从内部滚动的情况下使其全尺寸。

<iframe width="100%" height="700" src="url" frameborder="0" id="myIframe" scrolling="no"></iframe>

我想您应该将宽度和高度的单位从%更改为与所有设备兼容的视口,例如:将宽度设置为100vw ,这将设置 iframe 的宽度以覆盖整个视口宽度,因此宽度将是动态的,高度设置也是如此将它设置为100vh还可以添加样式,删除该 iframe 的宽度和高度属性,并添加与以下内容相同的内联样式,

<iframe style="width: 100vw; height:100vh" src="url" frameborder="0" id="myIframe" scrolling="no"></iframe>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM