zoukankan      html  css  js  c++  java
  • JS

    iframe:https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/iframe

    iframe 内容加载后不改变

    使用:onload="this.height=this.contentWindow.document.documentElement.scrollHeight"

    例如:

    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
    </head>
    <body>
      <h1>自适应高度</h1>
      <iframe srcdoc='<div style="height: 400px; 400px;background: #ddd;"></div>' frameborder="1" scrolling="no" width="100%" onload="this.height=this.contentWindow.document.documentElement.scrollHeight"></iframe>
    
      <h1>非自适应高度</h1>
      <iframe srcdoc='<div style="height: 400px; 400px;background: #ddd;"></div>' frameborder="1" scrolling="no" width="100%"></iframe>
    </body>
    </html>
    

    iframe 内容加载后改变

    定时改变 iframe 高度:

    setInterval(()=>{
      document.querySelector('iframe').height = window.frames[0].document.documentElement.scrollHeight;
    }, 200);
    

    例如:

    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
    </head>
    <body>
      <h1>自适应高度</h1>
      <iframe srcdoc='<button onclick="this.parentNode.appendChild(this.cloneNode())" style=" 100px; height: 100px;display: block;"></button>' frameborder="1" scrolling="no" width="100%" onload="this.height=this.contentWindow.document.documentElement.scrollHeight"></iframe>
    
      <h1>非自适应高度</h1>
      <iframe srcdoc='<button onclick="this.parentNode.appendChild(this.cloneNode())" style=" 100px; height: 100px;display: block;"></button>' frameborder="1" scrolling="no" width="100%"></iframe>
      <script>
        setInterval(()=>{
          document.querySelector('iframe').height = window.frames[0].document.documentElement.scrollHeight;
        }, 200);
      </script>
    </body>
    </html>
    
  • 相关阅读:
    HDU4911——归并排序——Inversion
    HDU5400——Arithmetic Sequence
    HDU5396——区间DP+排列组合——Expression
    DFS(连通块) ZOJ 2743 Bubble Shooter
    Codeforces Round #345 (Div. 2)
    Codeforces Round #344 (Div. 2)
    8VC Venture Cup 2016
    Manthan, Codefest 16
    DP(记忆化搜索) + AC自动机 LA 4126 Password Suspects
    全排列 UVA 11525 Permutation
  • 原文地址:https://www.cnblogs.com/jffun-blog/p/12046208.html
Copyright © 2011-2022 走看看