zoukankan      html  css  js  c++  java
  • 引入的iframe是跨域的, 如何控制其高度

    前提是你有编辑这个跨域的iframe的权限!!

    1. main-domain.html (main display HTML)
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>main-domain.html</title>
    </head>
    <body>
    <iframe id="js_iframe" src="crossdomain.html" frameborder="0" width="100%" height="0" scrolling="no"></iframe>
    </body>
    </html>
    
    2. other-domain.html (cross-domain iframe)
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <script src="jquery.js"></script>
      <title>other-domain.html</title>
    </head>
    <body>
    <iframe id="js_iframe_inner" src="" frameborder="0" width="0" height="0" scrolling="no"></iframe>
    </body>
    </html>
    <script>
    window.onload = function(){
      //top.js_if.height = $(document).height(); // if cross-domain will throws an exception.
      
      //other method:
      $('#js_iframe_inner').attr('src', 'other-main-domain.html?frameheight=' + $(document).height() );
    }
    </script>
    
    3.other-main-domain.html
    
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <script src="jquery.js"></script>
      <title>other-main-domain.html</title>
    </head>
    <body>
    </body>
    </html>
    <script>
    window.onload = function(){
      top.js_iframe.height = location.href.replace(/[^=]+=/, '');
    }
    </script>
    

      

  • 相关阅读:
    后台跨域(CORS)
    golang 处理TCP粘包问题
    使用axios 发送ajax 下载文件
    Golang:在Redigo的RedisPool上选择DB
    puppeteer添加代理
    mongodb 权限操作
    alpine下安装icu-dev
    golang 导出CSV文件中文乱码的问题
    shell笔记
    Convert rune to int
  • 原文地址:https://www.cnblogs.com/zlog/p/6037770.html
Copyright © 2011-2022 走看看