window.open() 子页返回值给父页

实现功能:parent.jsp 使用form post 传递数据给 son.jsp 并显示出来,然后 将 ‘fanhuizhi’ 返回给parent.jsp 并弹出:
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=UTF-8">
<title>Insert title here</title>
<script type = "text/javascript">

function openPostWindow(url, data, name)  
      {  
        var tempForm = document.createElement("form");  
          tempForm.id="tempForm1";  
          tempForm.method="post";  
          tempForm.action=url;  
          tempForm.target=name;  
          
          var hideInput = document.createElement("input");  
          hideInput.type="hidden";  
          hideInput.name= "content"
          hideInput.value= data;
          tempForm.appendChild(hideInput);   
          document.body.appendChild(tempForm);
          tempForm.submit();
          document.body.removeChild(tempForm);
     }
     
      function openWindow(name)  
      {  
         window.open('about:blank',name,'height=400, width=400, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');   
      }  


function openSon(){
window.open('son.html', 'structure', 'directories=no,height='+200+',width='+300+',location=no,menubar=no,resizable=no,scrollbars=yes,left='+200+',top='+100+',status=no,toolbar=no');
}

function _emailwarnflag(v){
alert(v);
}
</script>
</head>
<body>
<input type = "button" name = "button" value ="button" onclick = "openPostWindow('son.jsp','test','good');"/>
</body>
</html> 

第二:son.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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript" charset="utf-8">
function conf(){
//图片浏览结束返回值
opener._emailwarnflag('fanhuizhi');
window.close();
}
</script>
<%
String getStr = request.getParameter("content");
System.out.println(getStr+"------");
%>
<%=getStr %>
<input type="button" style="width:80px;" name="submit" value='ok' onClick="conf();"/>
<input type="button" style="width:80px;" name="reset" value='close' onClick="window.close();"/>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值