实现功能: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>