默认情况下,iframe会自带滚动条,不会全屏;想自适应iframe的方法

    1. 第一步,去掉滚动条
    2. 第二步,设置iframe的高为body的高

    iframe的用法技巧 https://www.yuque.com/lulongwen/web/cs332b

    1. import React, { useLayoutEffect, useRef, useState } from 'react';
    2. const initStyle = { width: '100%', height: '100%' };
    3. function InnerFrame() {
    4. const frameRef = useRef();
    5. const [style, setStyle] = useState(initStyle);
    6. useLayoutEffect(() => {
    7. const height = document.body.offsetHeight;
    8. setStyle({...initStyle, height });
    9. }, []);
    10. return (
    11. <iframe
    12. ref={frameRef}
    13. src="https://www.baidu.com"
    14. id="website"
    15. title="website"
    16. scrolling="no"
    17. frameBorder='0'
    18. style={style}
    19. />
    20. );
    21. }
    22. export default InnerFrame;