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();

  • 相关阅读:
    三层浅析及演示样例分析
    WIN7 以下创建cocos2d-x3.0+lua项目
    hdu1814 Peaceful Commission,2-sat
    卸载mysql残留
    OA 权限控制
    开源 java CMS
    BestCoder Round #3 A,B
    K-近邻算法python实现
    04-08移动字母
    移动web开发前准备知识了解(html5、jquery)笔记
  • 原文地址:https://www.cnblogs.com/dedeyi/p/2782657.html
Copyright © 2011-2022 走看看