window.opener 返回的是创建当前窗口的那个窗口的引用,也就是得到父级窗口的引用~
比如点击了index.htm上的一个链接而打开了helloWorld.htm,然后我们打算在helloworld.htm上输入一个值然后赋予index.htm上的一个id为“Name”的textbox中,就可以写为:
window.opener.document.getElementById("name").value = "helloWorld中输入的值";
使用例子:
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>用户信息</title>
<link href="./popedom_css/xtgl.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
/* 小数的四舍五入
* sswr(d,h):数值格式化函数,d要格式化的数字,h要保留的小数位数。
*/
function sswr(d,h){
d=(d*Math.pow(10,h)/Math.pow(10,h)).toFixed(h);
return d;
}
function selectUser(m){
var strarray=m.split(",");
window.opener.document.getElementsByName("givepopedomPeople")[0].value=strarray[0];
window.opener.document.getElementsByName("givepopedomPeopleName")[0].value=strarray[1];
window.close();
}
</script>
</head>
<body>
<form method="post" action="./givepopedom.do?mtype=seleUserXx" >
<table width="780" align="center" border=0 cellpadding="0" cellspacing="1" >
<tr>
<td>
<table width="750">
<tr>
<td class="title" align="center" valign="middle" height="20">用户信息</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" class="tab8">
<tr align="center" valign="middle" nowrap class="zt">
<th width="5%">选 择</th>
<th width="10%">用户ID</th>
<th width="10%">用户名称</th>
<th width="15%">用户真实姓名</th>
<th width="10%">所在部门</th>
</tr>
<c:forEach items="${userList}" var="userList" varStatus="i">
<tr align="center" valign="middle" class="editUp" nowrap>
<td ><input type="radio" name="foodId" value="${userList.userId},${userList.trueName}" onclick="selectUser(this.value)"></td>
<td >${userList.userId}</td>
<td >${userList.userName}</td>
<td >${userList.trueName}</td>
<td >${userList.organName}</td>
</tr>
</c:forEach>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
window.opener 使用示例
本文介绍了如何使用 window.opener 在弹出窗口中操作主窗口元素的方法,通过具体实例展示了如何将弹出窗口中的数据传回主窗口。
257

被折叠的 条评论
为什么被折叠?



