想iframe嵌入页面注入css

const loadComponyIframe = ()=>{
        let componyRelIframe = document.getElementById("componyIframe");
        let iframeDoc = componyRelIframe.contentWindow.document;
        let iframeHead = iframeDoc.getElementsByTagName('head');
        let linkTag = document.createElement('link');
        linkTag.id = 'newstyle';
        linkTag.href = `${APP_URL}/static/2209/iframe.css`;
        linkTag.setAttribute('rel', 'stylesheet');
        linkTag.setAttribute('type', 'text/css');
        iframeHead[0].appendChild(linkTag)
 }
<iframe onLoad={loadComponyIframe} id="componyIframe" className='model_iframe' width="100%" min-height="400px" border="none" src={orgUrl}></iframe>

  

posted @ 2022-06-15 09:15  iwen1992  阅读(665)  评论(0编辑  收藏  举报