js/jquery获取iframe子页面中元素的方法:

一、使用window.frames["iframe的ID"]获取元素

window.onload = function() {
var oIframe = window.frames["oIframe"].document.getElementById("getFrame");
console.log(oIframe);
}

注意:此处一定要加上window.onload或者DOMContentLoaded,也就是DOM加载或者页面加载完成后。

二、使用window.name获取元素

var oIDframe = window.oIframe.document.getElementById("getFrame");
console.log(oIDframe);
oIframe是iframe的name属性值,这种获取方法不必写在window.onload或者DOMContentLoaded中,请自行测试。

三、使用getElementById获取元素 
var oIdFrame = document.getElementById("oIframe").contentWindow.document.getElementById("getFrame");
console.log(oIdFrame);

使用document.getElementById获取本页面的iframe元素后,再获取iframe子页面的元素。这种获取方法不必写在window.onload或者DOMContentLoaded中

四、使用jquery获取

var ojIframe = $("#oIframe").contents().find("#getFrame").html();
console.log(ojIframe);

js/jquery  iframe子页面获取父页面元素的方法:

      一、使用js

var fatherEle = window.parent.document.getElementById("title");
console.log(fatherEle);

  二、使用jq

var fatherEleJq = $("#title",parent.document);
console.log(fatherEleJq);

父页面:

<div id="title">
index包含iframe子页面
</div>
<div id="parent">
<iframe name="oIframe" id="oIframe" src="iframe.html" frameborder="0" width="1000" height="562"></iframe>
</div>

iframe.html子页面:

<div id="getFrame">iframe</div>

参考链接:http://java-my-life.iteye.com/blog/1275205

父子页面之间元素相互操作(iframe子页面)的更多相关文章

  1. 父页面操作iframe子页面的安全漏洞及跨域限制问题

    一.父子交互的跨域限制 同域情况下,父页面和子页面可以通过iframe.contentDocument或者parent.document来交互(彼此做DOM操作等,如父页面往子页面注入css). 跨域 ...

  2. Iframe父页面与子页面之间的相互调用

    iframe元素就是文档中的文档. window对象: 浏览器会在其打开一个HTML文档时创建一个对应的window对象.但是,如果一个文档定义了一个或者多个框架(即:包含一个或者多个frame或者i ...

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

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

  4. JS中iframe子页面与父页面之间通信

    iframe子页面与父页面通信根据iframe中src属性是同域链接还是跨域链接,通信方式也不同. 一.同域下父子页面的通信 父页面parent.html <html> <head& ...

  5. js 在iframe子页面获取父页面元素,或在父页面 获取iframe子页面的元素的几种方式

    用JS或jquery访问页面内的iframe,兼容IE/FF 注意:框架内的页面是不能跨域的! 假设有两个页面,在相同域下. index.html 文件内含有一个iframe: XML/HTML代码 ...

  6. iframe父页面获取iframe子页面的元素 与 iframe子页面获取父页面元素

    一.在iframe子页面获取父页面元素代码如下:$('#objld', parent.document); 二.在父页面获取iframe子页面的元素代码如下:$("#objid", ...

  7. iframe子页面获取父页面元素的方法

    在iframe子页面获取父页面元素 代码如下: $.('#objld', parent.document); 在父页面获取iframe子页面的元素 代码如下: $("#objid" ...

  8. Js动态获取iframe子页面的高度////////////////////////zzzz

    Js动态获取iframe子页面的高度   Js动态获取iframe子页面的高度总结 问题的缘由 产品有个评论列表引用的是个iframe,高度不固定于是引发这个总结. 方法1:父级页面获取子级页面的高度 ...

  9. js之iframe子页面与父页面通信

    iframe子页面与父页面通信根据iframe中src属性是同域链接还是跨域链接,通信方式也不同. 一.同域下父子页面的通信 父页面parent.html <html> <head& ...

随机推荐

  1. [Android]使用Dagger 2依赖注入 - 自定义Scope(翻译)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5095426.html 使用Dagger 2依赖注入 - 自定义 ...

  2. [swift]NSURLSession

    一.简单说明 在iOS9.0之后,以前使用的NSURLConnection过期,苹果推荐使用NSURLSession来替换NSURLConnection完成网路请求相关操作. NSURLSession ...

  3. 0033 Java学习笔记-反射-初步1

    先看看通过反射能干嘛 示例:修改对象的private实例变量 package testpack; import java.lang.reflect.Field; public class Test1 ...

  4. 阿里技术协会好文推荐:Android绘制流程http://click.aliyun.com/m/8719/

    一.前言 1.1.C++界面库 MFC.WTL.DuiLib.QT.Skia.OpenGL.Android里面的画图分为2D和3D两种: 2D是由Skia 来实现的,3D部分是由OpenGL实现的. ...

  5. half extents

    blue line is hypotenuse From there you can simply linearly add Pi/4 to the angle (45 degrees), then ...

  6. pcl计算样点法向并显示

    利用最小二乘法估计样点表面法向,并显示 #include <pcl/point_types.h> #include <pcl/io/pcd_io.h> #include < ...

  7. Subsets

    Given a set of distinct integers, nums, return all possible subsets. Note: The solution set must not ...

  8. [LeetCode] K-th Smallest in Lexicographical Order 字典顺序的第K小数字

    Given integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n. N ...

  9. [LeetCode] Isomorphic Strings 同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  10. [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...