[英]Trying to pass a form value from pop-up window to Parent window in JS
Here is the Parent Code: 这是父代码:
<!DOCTYPE HTML>
<img id="header" src="www.google.com" alt="image">
<input type="text" id="txtName" />
<input type="button" value="Select" onclick="imageReplacement();" />
<script>
function imageReplacement() {
var imager = document.getElementsByTagName("img")[0]
popitup();
}
var popup;
function popitup() {
popup = window.open("Popup.html", "Popup", "width=300,height=100");
popup.focus();
return false
}
</script>
And here is the Pop-up code: 这是弹出代码:
<!DOCTYPE HTML>
<input name="imageNew" id="imageNew"></input>
<br />
<br />
<input type="button" value="Select" onclick="SetName();" />
<script type="text/javascript">
function SetName() {
var txtName = window.opener.document.getElementById("txtName");
txtName.value = document.getElementById("imageNew").value;
window.close();
}
</script>
Right now whatever value is set on the pop-up window is not being transferred to to the parent window. 现在,弹出窗口上设置的任何值都不会传输到父窗口。 Is this possible using javascript or do you need a web service to transfer the values?
是否可以使用javascript进行操作,或者您需要网络服务来传输值?
I have not tried whether it is possible to set a value of a html-element of a parent window within a child-window. 我还没有尝试过是否可以在子窗口中设置父窗口的html元素的值。 But you can definitely set an attribute of the parent window-object.
但是您绝对可以设置父窗口对象的属性。 Furthermore define a onclose handler fot the popup-window that gets called when the popup is closed within the parent-window.
此外,为弹出窗口定义一个onclose处理函数,当在父窗口中关闭弹出窗口时会调用该窗口。 When the close-handler is called you can extract the value of the attribute that you have set the the popup-window.
调用close-handler时,您可以提取已设置弹出窗口的属性的值。
Hope this helps a little bit and gives you some idea to overcome this problem. 希望这会有所帮助,并给您一些解决该问题的想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.