//父页面操作iframe里的内容
oInput.onclick=function(){
  var oBox = oIframe.contentWindow.document.getElementById("box");//获取window对象
  var oDocument = oIframe.contentDocument.getElementById("box");//获取document对象 
}
//iframe操作父页面里的内容
window.parent.document.getElementById('box');
window.top.document.getElementById('box');
window.onload=function(){
  //添加iframe;
  var oIframe = document.createElement('iframe');
  oIframe.src='iframe1.html';
  document.body.appendChild(iframe);
}
oIframe.onload=function(){
  // do something
  console.log(11);
}
//ie下绑定事件
oIframe.attachEvent("onload",function(){
 console.log(111);
})
//防止钓鱼网站
if(window.top!==window.self){
  window.top.href = window.location.href;
}
//撑高iframe的高度
function changeHeight(){
  oIframe.height = oIframe.contentWindow.document.body.offsetHeight;//jquery不行的话 用js试下document.getElementById('default').contentWindow.document.body.offsetHeight
}
changeHeight();
 
//iframe里操作父页面的高度
window.parent.document.documentElement.scrollHeight || window.parent.document.body.scrollHeight;
 
//CSS如何让iframe实现自适应高度的效果

<div class="resp-container">

    <iframe class="resp-iframe" src="https://www.youtube.com/embed/dQw4w9WgXcQ" gesture="media"  allow="encrypted-media" allowfullscreen></iframe>

</div>

.resp-container {

    position: relative;

    overflow: hidden;

    padding-top: 56.25%;

}

.resp-iframe {

    position: absolute;

    top: 0;

    left: 0;

    width: 100%;

    height: 100%;

    border: 0;

}

position: absolute;这将为iframe提供相对于包装器的位置,并将其放置在包装器的填充上。

top: 0并left: 0用于将iframe定位在容器的中心。

width: 100%并且height: 100%使IFRAME采取所有包装的空间。

完成后,你应该得到一个响应的iframe。

网上摘抄的一些笔记,如有错误,麻烦指正~

操作iframe的一些方法的更多相关文章

  1. JS 操作iframe

    很多人一直都有个想法,要是可以随心所欲的操作iframe就好了.这样静态页面也就有了相当于后台动态页面php,jsp,asp中include,require实现统一多页面布局的能力. 通过Javasc ...

  2. jquery 操作iframe的几种方法总结

    iframe在复合文档中经常用到,利用jquery操作iframe可以大幅提高效率,这里收集一些基本操作 DOM方法: 父窗口操作IFRAME:window.frames["iframeSo ...

  3. JQuery操作iframe父页面与子页面的元素与方法

    JQuery操作iframe父页面与子页面的元素与方法 JQUERY IFRAME 下面简单使用Jquery来操作iframe的一些记录,这个使用纯JS也可以实现. 第一.在iframe中查找父页面元 ...

  4. jquery操作iframe的方法:父页面和子页面相互操作的方法

    今天在弄jquery操作iframe中元素:先由iframe中的子页面b.html给外面的父页面a.html页面传值,再将a.html页面计算机的值放到b.html页面上,这里就用到子页面和父页面相互 ...

  5. 笔记:javascript操作iframe内的DOM元素,及调用iframe内的方法

    iframe相当于一个嵌入在网页内的浏览器,它与当前网页是隔离的. 但有时我们也需要在当前网页操作iframe内的元素或操作iframe内的javascript方法. 在网页内操作DOM元素,是使用d ...

  6. jQuery操作iframe中js函数的方法小结

    1.jquery操作iframe中的元素(2种方式) ? 1 2 var tha = $(window.frames["core_content"].document).find( ...

  7. jquery方法操作iframe元素

    操作iframe父元素 $("#rolesCtl",parent.document).find( 'button' ).trigger( 'click' ); 在父页面获取ifra ...

  8. js学习笔记:操作iframe

    iframe可以说是比较老得话题了,而且网上也基本上在说少用iframe,其原因大致为:堵塞页面加载.安全问题.兼容性问题.搜索引擎抓取不到等等,不过相对于这些缺点,iframe的优点更牛,跨域请求. ...

  9. 原生js与jquery操作iframe

    1  原生js获取iframe的window对象 //方法1 document.getElementById('iframeId').contentWindow; //方法2 window.frame ...

随机推荐

  1. 如何生成HLS协议的M3U8文件

    什么是HLS协议: HLS(Http Live Streaming)是由Apple公司定义的用于实时流传输的协议,HLS基于HTTP协议实现,传输内容包括两部分,一是M3U8描述文件,二是TS媒体文件 ...

  2. vc中播放mp3文件的方法小结

    一般播放MP3常见的有两种方法,一种是自己解码,另外一种用系统的库,比如MCI,当然如果可以用控件直接用个控件会更方便. 1.      使用mci #include <windows.h> ...

  3. RenderingPath 渲染路径

    http://blog.csdn.net/lichaoguan/article/details/42554821 RenderingPath 渲染路径 Deferred Lighting 延时光照 延 ...

  4. bzoj 1023 [SHOI2008]cactus仙人掌图 ( poj 3567 Cactus Reloaded )——仙人掌直径模板

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1023 http://poj.org/problem?id=3567 因为lyd在讲课,所以有 ...

  5. 2.JasperReports学习笔记2-创建简单的报表例子

    转自:http://www.blogjava.net/vjame/archive/2013/10/12/404908.html 一.创建简单的jrxml文件 这里可以手动创建jrxml文件,也可以使用 ...

  6. C# 处理Json

    下面是JSON对象转换为字符串 public static string ToJson(object obj) { try { JavaScriptSerializer serializer = ne ...

  7. Javascript作用域和变量提升

    下面的程序是什么结果? var foo = 1; function bar() { if (!foo) { var foo = 10; } alert(foo); } bar(); 结果是10: 那么 ...

  8. 03.generator

    generatorConfig.xml自动生成连接数据库的这些个公共类的方法. <?xml version="1.0" encoding="UTF-8" ...

  9. springboot thymeleaf org.xml.sax.SAXParseException错误

    SpringBoot越来越受欢迎,而官方推荐的模板是thymeleaf ,但是其语法太过严格,使用过程中一不留心就会出现org.xml.sax.SAXParseException错误 其中主要是下面这 ...

  10. 使用mahout fpgrowth算法求关联规则

    使用mahout fpgrowth 首先,这篇文章的内容大部分取自国外一篇博客Finding association rules with Mahout Frequent Pattern Mining ...