我写了两个网页opener.html和newwin.html,opener.html为父窗口,包含一个text文本框(初始值为beijing)和一个new window按钮,点击new window按钮可打开子窗口newwin.html,子窗口包含一个空白text文本框和一个get opener text按钮,点击按钮可让子窗口text文本框获取父窗口的text文本框内容。子窗口还有一个city下拉框,city改变触发onChange事件让父窗口text文本框获得city选项。
问题是:1、点击子窗口按钮后子窗口text没能获得父窗口text内容
2、city选项改变后父窗口text没能获得city内容
子窗口中两个函数都用到了window.opener.document来取得或改变父窗口text内容,我怀疑是window.opener.document没起到作用。有人能给解答一下吗?代码如下:
<!DOCTYPE html>
<html>
<head>
<title>opener.html</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=GB18030">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script language="javascript">
function newWin(){
window.open("newwin.html","new window","width=200,height=150,scrollbars=yes,resizable=no");
}
</script>
</head>
<body>
<form action="" name="openerform">
<input type="text" name="openertext" value="beijing">
<input type="button" value="New window" onClick="newWin()">
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>newwin.html</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=GB18030">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script language="javascript">
function getOpenerText(){
return opener.document.openerform.openertext.value;