You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Iframe滚动条?已设置scrolling="no"仍显示

解决iframe设置scrolling="no"仍显示滚动条的问题

你当前的iframe代码里虽加了scrolling="no",但这个旧属性在现代浏览器兼容性不佳,再加上几个细节问题,导致滚动条没被隐藏,可按以下方法解决:

  • 替换旧属性,用CSS样式控制:给iframe添加style="overflow: hidden;",同时保留scrolling="no"做兼容,覆盖浏览器默认行为。
  • 调整高度设置:height="auto"容易导致iframe高度未适配内容,触发溢出滚动。若知道嵌入内容的固定高度,直接设具体数值(比如height="600px");需要自适应的话,用JS动态获取嵌入页面的高度再赋值给iframe。
  • 处理嵌入页面的强制滚动:如果嵌入的目标页面自身设置了body { overflow: scroll; }这类强制显示滚动条的样式,你没法修改目标页面的话,可给iframe套一个容器,设置容器overflow: hidden,并把iframe高度设得比容器稍大,隐藏内部滚动条。

修改后的示例代码:

<iframe src="https://dispatchcenter.com/widgets/tall/" width="100%" height="600px" marginheight="0" frameborder="0" border="0" scrolling="no" style="overflow: hidden;"></iframe>

自适应高度的JS示例(需给iframe加idtargetIframe):

const iframe = document.getElementById('targetIframe');
iframe.onload = function() {
  this.style.height = this.contentWindow.document.body.scrollHeight + 'px';
};

内容的提问来源于stack exchange,提问作者Asmi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 03:55:31