iframe高度自适应

北城余情 提交于 2019-12-02 05:19:18

1)不跨域 直接获取到iframe中的内容

定时器设置iframe高度

  changeIframeHeight = () => {
    const reinitIframe =  () => {
      let count = 0;
      return () => {
        try {
          const height = this.iframe.contentWindow.document.querySelector('.ant-table-body').offsetHeight + 5
          this.iframe.height = height > 150 ? height : 150;
          count += 1
        } catch (ex) {
          console.log('ex: ', ex);
        }
        return count
      };
    }

    let resetCount = 0
    const reset = reinitIframe()
    const timer = setInterval(() => {
      if (resetCount > 15) {
        clearInterval(timer)
      }
      resetCount = reset()
    }, 300);
  };
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!