Property ‘contentWindow‘ does not exist on type HTMLElement,类型htmlelement上不存在contentwindow属性

Property ‘contentWindow‘ does not exist on type HTMLElement,类型htmlelement上不存在contentwindow属性_第1张图片

一、问题

Property 'contentWindow' does not exist on type HTMLElement

二、解决方法

 /**
  *  Property 'contentWindow' does not exist on type HTMLElement - 出现这个问题的处理方法;
  *  start
  */

    const isIFrame = (input: HTMLElement | null): input is HTMLIFrameElement =>
     input !== null && input.tagName === 'IFRAME';

     /**
      *  iframs: 获取document里的所有iframe标签;
      *  iframe: 获取你所需要的iframe标签;
      *  start
      */

       const iframes = parent.document.getElementsByTagName('iframe');
       const iframe = iframes[0];
 
       /**
        *  将粘贴的img标签里的src值,用图片上传返回的url值 【强制】 替换;
        *  强制替换是因为图片此时已经显示在富文本里了;
        *  start
        */
          if (isIFrame(iframe) && iframe.contentWindow) {
              iframe.contentWindow.document
                                .getElementById(imgId)
                                .setAttribute('src', imageUrl);
             }



        /** end */


     /** end */


  /** end */

 

参考: https://stackoverflow.com/questions/56551644/property-contentwindow-does-not-exist-on-type-htmlelement-sending-from-one-s

你可能感兴趣的:(javascript,html,typescript,dom)