直接给出代码。
1.父窗口的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>父窗口</title>
<script type="text/javascript">
var i = 1;
function look(Height,Width){
var ScreenWidth = (screen.availWidth - Width) / 2;
var ScreenHeight = (screen.availHeight - Height )/ 2;
var nw = window.open('show.jsp?flag='+i,"nw",'height='+ScreenHeight+',width='+ScreenWidth+',top='+ScreenHeight+',left='+ScreenWidth+',toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no, status=no');
nw.document.title = "子窗口";
i++;
}
</script>
</head>
<body>
<input type="button" id="bnt" value="查看" onclick="look(350,250);"/>
<div id="myDiv">你选的物品有:</div>
<span id="Msg" style="display:none;color:green;"></span>
</body>
</html>
2.子窗口的jsp代码(show.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>子窗口</title>
<script type="text/javascript">
function look(value){
window.opener.document.getElementById("bnt").value="重新查看";
window.opener.document.getElementById("Msg").style.display="block";
window.opener.document.getElementById("Msg").innerHTML=value;
window.close();
}
</script>
</head>
<body>
<p>父窗口穿过来的参数
<%= request.getParameter("flag") %>
</p><br>
<select id="sel" onchange="look(this.value);">
<option value="0">请选择商品</option>
<option value="笔记本">笔记本</option>
<option value="手机">手机</option>
<option value="数码相机">数码相机</option>
</select>
</body>
</html>
上面的代码中当用nw.document.title = "子窗口",设置子窗口的title时,不知道为什么总是设置不成功,子窗口的title总是显示"web browser",并且大家都看到了我在上面的子窗口的<title>标签中已经设置了title,但子窗口里页面没有显示出来。如果谁能够告诉我问题的所在,将感谢不尽!