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的球,每个球都有唯一的编号.这些球被排成两种序列,分别为A.B序列,现在需要重新寻找一个球的序列l,对于这个子序列l中任意的两个球,要求j,k(j<k),都要求满足lj在A中位置 ...

  2. Window环境下搭建MyEclipse+Tomcat+MAVEN+SVN

    1.JDK的安装 首先下载JDK,这个从sun公司官网(http://www.oracle.com/)可以下载,根据自己的系统选择64位还是32位,安装过程就是next一路到底.安装完成之后当然要配置 ...

  3. git之install

    一.window安装 1.下载路径 https://git-for-windows.github.io/ 2.如何在windows下安装GIT_百度经验 3.做完上面两部打开Git bash即可执行g ...

  4. php导出csv数据在浏览器中输出提供下载或保存到文件的示例

    来源:http://www.jb51.net/article/49313.htm 1.在浏览器输出提供下载 /** * 导出数据到CSV文件 * @param array $data 数据 * @pa ...

  5. centos下安装nginx

    1.yum install nginx     安装nginx 2.service nginx start  启动nginx 3.然后进入浏览器,输入http://Ip/测试,如果看到 Welcome ...

  6. PL/sql developer连接数据库的问题以及oracle数据库中文乱码的问题

    今天第二次配置PL/sql developer,表示很蛋疼,昨天因为动了一个东西然后莫名其妙的就再也连接不了数据库,总是显示各种错误,我动的东西是因为中文会显示乱码,(因为我是用32位的PL/sql ...

  7. iOS开发——高级篇——传感器(加速计、摇一摇、计步器)

    一.传感器 1.什么是传感器传感器是一种感应\检测周围环境的一种装置, 目前已经广泛应用于智能手机上 传感器的作用用于感应\检测设备周边的信息不同类型的传感器, 检测的信息也不一样 iPhone中的下 ...

  8. [转载]javascript创建对象的几种方式

    原文链接:http://qingfeng825.iteye.com/blog/1935648 1. 工厂方法:能创建并返回特定类型对象的工厂函数(factory function). function ...

  9. 极客DIY:制作一个可以面部、自主规划路径及语音识别的无人机

    引言 现在大部分无人机厂商都会为第三方开发者提供无人机API接口,让他们更容易地开发无人机飞行控制应用程序,让无人机想怎么玩就怎么玩.有的API接口可以帮助开发者开发基于Web版的APP.手机APP甚 ...

  10. 试用vSphere 6(三):安装vCenter 6(独立数据库)之:vCenter安装与配置

    ------------------------------------------ 一.VMware vSphere 6(RC版)安装配置系列文章: 1.试用vSphere 6(一):安装ESXi ...