window.parent针对iframe,window.opener针对window.open

父页面parent.jsp:

 <%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function openSubWin()
{
var _width = 300 ;
var _height = 200 ;
var _left = (screen.width - _width) / 2 ;
var _top = (screen.height - _height) / 2 ;
window.open("third.jsp",null,
"height=" + _height + ",width=" + _width + ",status=no,toolbar=no,menubar=no,location=no,resizable=yes,left=" + _left + ",top=" + _top);
}
</script> <body>
<form name="form1"> name:<input type="text" name="username" id="username" value="haohao" />
<input type="button" value="弹出子页面" onClick="openSubWin();"> </form>
<hr/>
<div>
<iframe src="child.jsp"></iframe>
</div> </body>
</html>

子页面child.jsp:

 <script type="text/javascript">

 function fun(){
alert(window.parent.document.getElementById("username").value);
window.parent.document.getElementById("username").value="来自子页面的数据";
}
</script>
</head>
<body>
<p style="color:red;">子页面</p>
<input type="button" value="dianji" onclick="fun()"/>

运行后界面:

点击子页面按钮“dianji” :

页面third.jsp:

 <script type="text/javascript">
function UpdateParent()
{
var _parentWin = window.opener ;
_parentWin.form1.username.value = "来自子窗口 的参数" ;
}
</script>
<input type="button" name="button" id="button" value="更新主页面的UserName内容" onClick="UpdateParent();">

点击按钮“更新主页面的UserName内容”改变parent.jsp页面的值

window.opener是当前页面A通过open方法弹出一个窗口B,那在B页面上 window.opener就是A

window.parent是当前页面C通过location.href转到新的页面D,那在D页面上window.parent就是C

或者是页面E里套一个frame为F,那F页面的window.parent就是E

如何页面A里套一个frame为B,B页面有个按钮,点击open一个页面C,那么在C页面window.opener.parent就是A

window.parent 与 window.opener的更多相关文章

  1. JavaScript中,window.opener是什么?window.parent和window.opener有啥区别?

    来自CSDN的问答: window.opener是什么啊? ++++++++++++++++++++++++++++++++++++++++++++++++++ 弹出本窗体的句柄 比如你想点一个按钮直 ...

  2. window.parent与window.opener的区别

    有这样一个需求,弹出一个新窗口 并从该新页面的select选择框中选择需要的类别,再返回到之前的父窗口页面的某个文本框中.这里就要用到window.parent和window.opener 如题两种方 ...

  3. (转)window.parent和window.opener区别

    下面一段代码是关于window.parent和window.opener区别 来讲的,我们如果要用到iframe的值传到另一框架就要用到window.opener.document.getElemen ...

  4. window.parent与window.openner区别介绍

    今天总结一下js中几个对象的区别和用法: 首先来说说 parent.window与top.window的用法 "window.location.href"."locati ...

  5. window.parent与window.openner

    window.parent与window.openner区别介绍 作者: 字体:[增加 减小] 类型:转载 今天总结一下js中几个对象的区别和用法,对这几个概念混淆的朋友可以看看 今天总结一下js中几 ...

  6. window.parent与window.opener的区别与使用

    window.parent 是iframe页面调用父页面对象 举例: a.html 如果我们需要在b.html中要对a.html中的username文本框赋值(就如很多上传功能,上传功能页在ifrma ...

  7. window.parent与window.opener、window.showModalDialog的区别 opener和showModalDialog刷新父页面的方法

    项目中使用案例: 父窗体 <s:form namespace="/forexagent" id="listSearchForm" name="t ...

  8. window.parent与window.openner 之前的总结

    今天总结一下js中几个对象的区别和用法: 1.首先来说说 parent.window与top.window的用法 "window.location.href","loca ...

  9. window.parent 与 Window.top

    window.parent 返回当前窗口的父窗口对象. 如果一个窗口没有父窗口,则它的 parent 属性为自身的引用. 如果当前窗口是一个 <iframe>, <object> ...

随机推荐

  1. 黄学长模拟day1 大逃亡

    给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上,矩形的行号从0到X-1,列号从 ...

  2. jquery 使用textarea

    问题: 若在textarea标签中键入一个回车时,将插入2个字符\n\r ,将在datagrid不能正确显示. \n: 回车符 \r: 换行符  解决方案: txt = txt.Replace(&qu ...

  3. nyoj 10 skiing 搜索+动归

    整整两天了,都打不开网页,是不是我提交的次数太多了? nyoj 10: #include<stdio.h> #include<string.h> ][],b[][]; int ...

  4. Mac Pro 软件收藏

    记录下Pro Mac中安装过的软件: 编号 软件名 功能说明 1 QQ   2 微信   3 搜狗输入法   4 Chrome 浏览器  Chrome 及其 插件“个性化设置”备份 5 360云盘   ...

  5. redis-string-统计

    package com.ztest.redis.string; import org.junit.Test; import redis.clients.jedis.Jedis; import com. ...

  6. httpd服务访问控制

    客户机地址限制 通过配置Order.Deny from.Allow from 来限制客户机 allow.deny :先"允许"后"拒绝" ,默认拒绝所有为明确的 ...

  7. Spring 事务知识

    1.1  Spring注解的各种行为 事物传播注解: @Transactional(propagation=Propagation.REQUIRED) (常用) 如果有事务, 那么加入事务, 没有的话 ...

  8. Unity手游之路<十一>资源打包Assetbundle

    http://blog.csdn.net/janeky/article/details/17652021 在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制 ...

  9. Caffe学习系列(8):solver及其配置

    solver是caffe的核心. net: "examples/mnist/lenet_train_test.prototxt" test_iter: 100 test_inter ...

  10. PHP中九大缓存技术总结

    PHP缓存包括PHP编译缓存和PHP数据缓存两种.PHP是一种解释型语言,属于边编译边运行的那种.这种运行模式的优点是程序修改很方便,但是运行效率却很低下.PHP编译缓存针对这种情况做改进处理,使得P ...