zoukankan      html  css  js  c++  java
  • js对iframe的操作

    1、获取iframe中页面中的window对象

      contentWindow  <iframe src="iframe1.htm" id="iframe1"></iframe>  

      contentWindow属性。(在chrome中必须在服务器环境下)  

      oIframe.contentWindow.document.getElementById('iframe1-div');  

    2、操作document对象 contentDocument IE8+  

      oIframe.contentDocument.getElementById('iframe-div');  

    3、iframe中操作父级内容

      window.parent.document.getElementById

    4、获取最顶层的window对象:

       window.top最顶层

    5、iframe加载事件

      onload  oIframe.onload=function()  {     }  

       在IE中要绑定才行  oIframe.attachEvent('onload',function(){     })  

    6、防止被嵌套(防钓鱼)  

      if(window!=window.top)  {   window.top.location.href=location.href;  }  

    7、获取iframe中内容的高度宽度  

      oIframe.contentWindow.document.body.offsetHeight;    

        function changeHeight()  {   setTimeout(function(){    oIframe.height=oIframe.contentWindow.document.body.offsetHeight;   },100);  }  

    8、调用iframe中的js方法  

      document.getElementById('iframeid').contentWindow.subFun();

  • 相关阅读:
    Python paramiko安装报错
    Python 函数返回值类型
    python 数据类型
    python — 模块(二)
    python — 模块(一)
    python 总结
    python 小知识3
    python 小知识3
    python 小知识2
    python — 计算机基础知识
  • 原文地址:https://www.cnblogs.com/dedeyi/p/2782657.html
Copyright © 2011-2022 走看看