window.parent 与 window.opener
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的更多相关文章
- JavaScript中,window.opener是什么?window.parent和window.opener有啥区别?
来自CSDN的问答: window.opener是什么啊? ++++++++++++++++++++++++++++++++++++++++++++++++++ 弹出本窗体的句柄 比如你想点一个按钮直 ...
- window.parent与window.opener的区别
有这样一个需求,弹出一个新窗口 并从该新页面的select选择框中选择需要的类别,再返回到之前的父窗口页面的某个文本框中.这里就要用到window.parent和window.opener 如题两种方 ...
- (转)window.parent和window.opener区别
下面一段代码是关于window.parent和window.opener区别 来讲的,我们如果要用到iframe的值传到另一框架就要用到window.opener.document.getElemen ...
- window.parent与window.openner区别介绍
今天总结一下js中几个对象的区别和用法: 首先来说说 parent.window与top.window的用法 "window.location.href"."locati ...
- window.parent与window.openner
window.parent与window.openner区别介绍 作者: 字体:[增加 减小] 类型:转载 今天总结一下js中几个对象的区别和用法,对这几个概念混淆的朋友可以看看 今天总结一下js中几 ...
- window.parent与window.opener的区别与使用
window.parent 是iframe页面调用父页面对象 举例: a.html 如果我们需要在b.html中要对a.html中的username文本框赋值(就如很多上传功能,上传功能页在ifrma ...
- window.parent与window.opener、window.showModalDialog的区别 opener和showModalDialog刷新父页面的方法
项目中使用案例: 父窗体 <s:form namespace="/forexagent" id="listSearchForm" name="t ...
- window.parent与window.openner 之前的总结
今天总结一下js中几个对象的区别和用法: 1.首先来说说 parent.window与top.window的用法 "window.location.href","loca ...
- window.parent 与 Window.top
window.parent 返回当前窗口的父窗口对象. 如果一个窗口没有父窗口,则它的 parent 属性为自身的引用. 如果当前窗口是一个 <iframe>, <object> ...
随机推荐
- 【Hadoop】HDFS的运行原理
博文已转移,请借一步说话http://www.weixuehao.com/archives/596 简介 HDFS(Hadoop Distributed File System )Hadoop分布式文 ...
- WCF基础知识
根据微软官方的解释,WCF(之前的版本名为“Indigo”)是使用托管代码建立和运行面向服务(Service Oriented)应用程序的统一框架.它使得开发者能够建立一个跨平台的安全.可信赖.事务性 ...
- wordpress自动清理评论回收站
有时wordpress的垃圾评论实在让人心烦,杂草难除根,footprint吹又生.如果你有心情的话会一个个把垃圾评论放入回收站,但是时间一长,回收站里的东西越堆越多,你可以点击回收站,然后再点一下e ...
- objective-c-sort-keys-of-nsdictionary-based-on-dictionary-entries
NSArray *keys = [someDictionary allKeys]; NSArray *sortedKeys = [keys sortedArrayUsingComparator:^NS ...
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial
题目链接:http://codeforces.com/contest/515/problem/C 给出一个公式例如:F(135) = 1! * 3! * 5!; 现在给你一个有n位的数字a,让你求这样 ...
- C++输入输出流
一.C++输入输出流的含义 以前所用到的输入和输出,都是以终端为对象的,即从键盘输入数据,运行结果输出到显示器屏幕上.从操作系统的角度看,每一个与主机相连的输入输出设备都被看作一个文件.程序的输入指的 ...
- 表单select相关
selectedIndex 属性可设置或返回下拉列表中被选选项的索引号. options[] 返回包含下拉列表中的所有选项的一个数组. add()向下拉列表添加一个选项. blur()从下拉列表移开焦 ...
- 基于jquery的-获取短信验证码-倒计时
在制作短信验证的时候,需要做一个获取短信按钮,点击后显示倒计时, html代码如下: <input class="gain" type="button" ...
- bug-android之INSTALL_FAILED_NO_MATCHING_ABIS
bug描述: 经常在网络上下载一些实例,自己研究 ,运行时不时会出现这个bug: Installation error: INSTALL_FAILED_NO_MATCHING_ABIS bug解决方案 ...
- 5.5---整数A转成整数B(CC150)
自己的: public static int calcCost(int A,int B){ int ans = 1; int temp = A ^ B; while(temp != 1){ if(te ...