html代码使用 iframe 不能完全显示,代码如下
<div
className={styles.knowledgeRouteStyle}
style={{ width: '100%', height: '95%', touchAction: ' none', overflowY: 'scroll' }}
>
<iframe
id="iframe_detl"
name="iframe_a"
frameBorder="0"
scrolling="yes"
style={{ padding: '0', width: '100%' }}
src={`${apiCode.zskDetailHtmlApi}FTTH常见故障解决办法`}
></iframe>
</div>
一定要 先在 iframe 的父标签上加上高度
使用 React 框架,但是意思是一样的
useEffect(() => {
setInterval(() => {
reinitIframe();
}, 200);
}, []);
const reinitIframe = () => {
var iframe = document.getElementById('iframe_detl');
try {
var bHeight = iframe?.contentWindow.document.body.scrollHeight;
var dHeight = iframe?.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
} catch (ex) {}
};