zoukankan      html  css  js  c++  java
  • iframe自适应,跨域,JS的document.domain

    以前了解了下 没仔细用 网上找的几个都不太合适

    3个步骤

    1.再父窗口加上document.domain(也就是调用IFRAME的那个窗口)

    XML/HTML代码
    1. <script type="text/javascript">  
    2. document.domain = "cnmo.com";   
    3. </script>  

    2.在子窗口加上下边代码(也就是IFRAME本身里边)

    XML/HTML代码
    1.  <script type="text/javascript">  
    2. document.domain = "cnmo.com";   
    3. </script>  
    4. <script type="text/javascript">  
    5. function iframeAutoFit()   
    6. {   
    7.      try   
    8.      {   
    9.          if(window!=parent)   
    10.          {   
    11.              var a = parent.document.getElementsByTagName("iframe");   
    12.              for(var i=0; i<a.length; i++)   
    13.              {   
    14.                  if(a[i].contentWindow==window)   
    15.                  {   
    16.                      var h1=0, h2=0, d=document, ddd=d.documentElement;   
    17.                      a[i].parentNode.style.height = a[i].offsetHeight +"px";   
    18.                      a[i].style.height = "10px";   
    19.   
    20.                      if(dd && dd.scrollHeight) h1=dd.scrollHeight;   
    21.                      if(d.body) h2=d.body.scrollHeight;   
    22.                      var h=Math.max(h1, h2);   
    23.   
    24.                      if(document.all){h += 4;}   
    25.                      if(window.opera){h += 1;}   
    26.                      a[i].style.height = a[i].parentNode.style.height = h +"px";   
    27.                  }   
    28.              }   
    29.          }   
    30.      }   
    31.      catch (ex){}   
    32. }   
    33. if(window.attachEvent)   
    34. {   
    35.      window.attachEvent("onload",   iframeAutoFit);   
    36. }else if(window.addEventListener)   
    37. {   
    38.      window.addEventListener('load',   iframeAutoFit,   false);   
    39. }   
    40. </script>    

    3.细节问题 IFRAME外边加个DIV,否则火狐下有问题,宽度设置好 否则他们都有问题

    XML/HTML代码
    1. <div style="100%;margin:0 0 10px 0;">   
    2. <iframe align='middle' src='http://comments.cnmo.com/iframe_comment.php?kindid=9&articleid=<?=$pic_id?>&tw=620&style=11&font_num=180&pagesize=3' frameborder='0' marginwidth='0' marginheight='0' width='100%' scrolling='no' height='450px' style='margin-top:15px;'></iframe>   
    3. </div>  

    这样就好了 有问题 也是微调下就好了

     
  • 相关阅读:
    【转】VS2010中 C++创建DLL图解
    [转]error: 'retainCount' is unavailable: not available in automatic reference counting mode
    [转]关于NSAutoreleasePool' is unavailable: not available in automatic reference counting mode的解决方法
    【转】 Tomcat v7.0 Server at localhost was unable to start within 45
    【转】Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If
    【转】SVN管理多个项目版本库
    【转】eclipse安装SVN插件的两种方法
    【转】MYSQL启用日志,和查看日志
    【转】Repository has not been enabled to accept revision propchanges
    【转】SVN库的迁移
  • 原文地址:https://www.cnblogs.com/olartan/p/1572264.html
Copyright © 2011-2022 走看看