【发布时间】:2019-01-31 11:18:28
【问题描述】:
我想将数据从子窗口传递到父窗口。
问题是子窗口打开但用户输入的值没有传给父窗口
parent.html
<form action="" method="post" name="f1">
<table border="0" cellpadding="0" cellspacing="0" width="550">
<tr>
<td>
<font face="Verdana" size="2">
Your Name
</font>
<input name="p_name" size="8" type="text">
<a href="javascript:void(0);" name="My Window Name" onclick='window.open("child.html","Ratting", "width=550,height=170,left=150,top=200,toolbar=1,status=1,");' title=" My title here ">
Click here to open the child window
</a>
</input>
</td>
</tr>
</table>
</form>
child.html
<html>
<head>
<script langauge="javascript">
function post_value() {
opener.document.f1.p_name.value = document.frm.c_name.value;
self.close();
}
</script>
<title>
(Type a title for your page here)
</title>
</head>
<body>
<form action="" method="post" name="frm">
<table border="0" cellpadding="0" cellspacing="0" width="250">
<tr>
<td align="center">
Your name
<input name="c_name" size="12" type="text" value="test">
<input onclick="post_value();" type="button" value="Submit">
</input>
</input>
</td>
</tr>
</table>
</form>
</body>
</html>
如何将数据从子窗口传递到父窗口?
【问题讨论】:
-
这似乎对我有用。我用你的代码创建了一个plnkr.co/edit/ves7Xm7sDP3CQAczeMjr。什么对你有不同的作用?
-
@mehtankush 在 chrome 和 opera 等网络浏览器中不起作用,但在 IE 中它可以工作。你知道一些问题吗?为什么 chrome 和 opera 不起作用?
-
@derisumargo 它可以在 chrome 中找到。
标签: javascript html