javascript 获取iframe里页面中元素值的方法

IE方法:
document.frames['myFrame'].document.getElementById('test').value;

火狐方法:
document.getElementById('myFrame').contentWindow.document.getElementById('test').value;

IE、火狐方法:

 function getValue(){

         var tmp = '';

         if(document.frames){

                tmp += 'ie哥说:';

                tmp += document.frames['myFrame'].document.getElementById('test').value;

         }else{

                tmp = document.getElementById('myFrame').contentWindow.document.getElementById('test').value;

         }

         alert(tmp);

    }

示例代码:
a.html页面中的代码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
javascript 获取iframe里页面中元素的值 测试
</title>
</head>
<body>
<iframe id="myFrame" src='b.html' style="width:300px;height: 50px;"></iframe>
<input type="button" id="btn" onclick="getValue()" value="test" >
<script type="text/javascript">
function getValue(){
var tmp = '';
if(document.frames){
tmp += 'ie哥说:';
tmp += document.frames['myFrame'].document.getElementById('test').value;
}else{
tmp = document.getElementById('myFrame').contentWindow.document.getElementById('test').value;
}
alert(tmp);
}
</script>
</body>
</html>

  b.html页面中的代码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
我是 iframe内的页面
</title>
</head>
<body>
<input type='text' id="test" value='欢迎访问:justflyhigh.com'>
</body>
</html>

  

  

 

javascript 获取iframe里页面中元素值的方法 关于contentWindow和contentDocumen的更多相关文章

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

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

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

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

  3. javascript动态改变当前页面中元素的状态行为

    function Datea() { var timed = document.getElementById('timed'); var t = setInterval(function TDate( ...

  4. javascript获取iframe框架中页面document对象,获取子页面里面的内容,iframe获取父页面的元素,

    javascript获取iframe框架中,加载的页面document对象 因为浏览器安全限制,对跨域访问的页面,其document对象无法读取.设置属性 function getDocument(i ...

  5. Js获取iframe子页面全局变量

    项目中通过iframe内嵌了一个子页面,子页面定义了一些全局变量,父页面需要获取子页面的全局变量,做了一些测试(我的环境IE10和Firefox32.0.3),得出如下结论: IE下: window. ...

  6. 获取Iframe页面高度并赋值给Iframe以及获取iframe里的元素

    最近接手了别人的项目,别人用到了iframe,自己在实战中总结了一些关于iframe的小问题. 获取Iframe页面高度并赋值给Iframe Html <iframe name="co ...

  7. 使用JavaScript设置、获取父子页面中的值

    一:获取父页面中的值 有二种方法windows.open()和windows.showModalDialog() 1.windos.open(URL,name,reatures,replace) 再父 ...

  8. javascript 获取父页面中元素对象方法

    父页面中: <input type="hidden" id="areaID" value="test1"> <iframe ...

  9. jQuery 获取jsp页面中用iframe引入的jsp页面中的值

    <iframe scrolling="no" src="<c:url value='/unitBaseperson/view.do?para=9&op ...

随机推荐

  1. Remote error: Provider not exported: DataSetProvider1

    Remote error: Provider not exported: DataSetProvider1 是服务端的问题,ServerMethodsUnit1.cpp窗体上添加DataSetProv ...

  2. 如何将查出的日期Data类型以Json格式输出到前端

    方法一 在返回的实体的属性中加上注解 // 创建时间    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")    private ...

  3. Java并发编程之——Amino框架

    Amino框架是一个采用无锁方式实现并行计算的框架,可惜的是,网上关于Amino框架的介绍甚少.根据所掌握的资料,稍微总结一下: 1. 锁机制到无锁机制 锁机制可以确保程序和数据的线程安全,但是锁是一 ...

  4. Python迭代dict的value

    我们已经了解了dict对象本身就是可迭代对象,用 for 循环直接迭代 dict,可以每次拿到dict的一个key. 如果我们希望迭代 dict 对象的value,应该怎么做? dict 对象有一个  ...

  5. Nginx负载均衡高可用

    1.   Nginx负载均衡高可用 首先介绍一下Keepalived,它是一个高性能的服务器高可用或热备解决方案,Keepalived主要来防止服务器单点故障的发生问题,可以通过其与Nginx的配合实 ...

  6. 英文单词cipher 和password的区别,用法有什么不同,

    ['saɪfə(r)] cipher 指一套密码系统,比如电影<风声>中破译的那个系统叫cipher:password 则指进入的指令,比如你的qq密码,电脑密码等叫password.总之 ...

  7. Hibernate一对多操作

    --------------------siwuxie095 Hibernate 一对多操作 以客户和联系人为例,客户是一,联系人是多 即 一个客户里面有多个联系人,一个联系人只能属于一个客户 注意: ...

  8. Java核心技术-Java的基本程序设计结构

    1.一个简单的Java应用程序 public class FirstSample { public static void main(String[] args) { System.out.pring ...

  9. Java-Excel文件读取

    import java.io.File; import java.io.IOException; import org.testng.annotations.DataProvider; import ...

  10. 377. Combination Sum IV 返回符合目标和的组数

    [抄题]: Given an integer array with all positive numbers and no duplicates, find the number of possibl ...