window.opener.document

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'windowOpener.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	<[reference: http://www.jb51.net/article/22930.htm]>
	<[reference: http://www.cnblogs.com/meteoric_cry/archive/2010/10/14/1851093.html]>
	<[reference: http://www.dynamicdrive.com/forums/showthread.php?42873-window-open()
	                  -amd-window-opener-document-JavaScript-Problem-in-FireFox]>
	
	Here, go and view some basic knowledge about window open:
	window.open(pageURL,name,parameters) 
        pageURL 为子窗口路径 
        name 为子窗口句柄 
        parameters 为窗口参数(各参数用逗号分隔) 
       <SCRIPT> 
        window.open ('page.html','newwindow',
        'height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')
                 
       here some ways to open a new window:
       a) <body οnlοad="openwin()"> // 浏览器读页面时弹出窗口 
       b) <body οnunlοad="openwin()"> // 浏览器离开页面时弹出窗口
       c) <a href="#" οnclick="openwin()">打开一个窗口</a> 
       d) <input type="button" οnclick="openwin()" value="打开窗口"> 
    
       QUESTION:
       例如: 页面AAA.htm 用 window.open方式弹出页面 BBB.htm ,在页面BBB.htm上选择一个值,确定关闭窗口后将选择的这个值返回到父窗口AAA.htm.
       AAA.htm得到返回的值后,给本页面上的文本框赋值 
        
       ANSWER IS:
       BBB.htm页面中加入下面代码: 
       window.opener.document.getElementById("theTextAreaId").value = document.getElemnetById("theSelectId").value ; 

       window.opener 的用法 
      <[window.opener 返回的是创建当前窗口的那个父窗口的引用 ]>,比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后
       赋予a.htm上的一个id为"name"的textbox中,就可以写为: 
       window.opener.document.getElementById("name").value = "输入的数据";
    
       window.open('','_parent','');         
       window.close();
       -->
    <script type="text/javascript">
     function openwin() 
     { 
          window.open("child.jsp", "newwindow", 
          "height=100, width=400, toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
     } 
     
     function taletoTb(itemStr) 
     { 
          newRow = opener.document.all.itemTb.insertRow(opener.document.all.itemTb.rows.length); 
          rowCnt = opener.document.all.itemTb.rows.length; 
          newCell = newRow.insertCell(); 
          newCell.insertAdjacentHTML('BeforeEnd','<div align="center">'+itemCode+'</div>'); 
          newCell = newRow.insertCell(); 
          newCell.insertAdjacentHTML('BeforeEnd','<div align="center">'+itemName+'</div>'); 
          newCell = newRow.insertCell(); 
          newCell.insertAdjacentHTML('BeforeEnd',''); 
      }
    </script>
  </head>
  
  <body>
   <form id="qryFrm" action="">
      <table id="showShoppingList" name="showListTable" border="1">
          <tr>
            <td>item:<input type="text" name="shoppingItem"></td>
            <td>price:<input type="text" name="shoppingItemPrice" id="shoppingItemPrice"></td>
          </tr>
      </table>
      <input type="button" οnclick="openwin()" value="open_new"> 
   </form>
  </body>
</html>

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <script type="text/javascript">
      function grant_value_parent()
      {
         var price = document.getElementById("price").value;
         window.opener.document.getElementById("shoppingItemPrice").value = price;
      }
    </script>
  </head>
  
  <body>
    <table id="para-01" name="para-01">
       <tr id="tr1" name="tr1">
        <td>price:<input type="text" name="price" id="price"></td>
       </tr>
    </table>
    <input type="button" οnclick="grant_value_parent()" value="grant_value"> 
  </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值