admin管理员组文章数量:1318573
I want my parent window to have button that opens child window. Child window should have an input text box and a button(Named Copy). Whatever i enter text in child window textbox and click Copy button, the child window should close and entered name should appear on parent window.
I am trying below approach but can't understand how to retrieve enter value on parent.
p>Click the button to create a window and then display the entered name on parent window.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var myWindow = window.open("", "MsgWindow", "width=200,height=200");
myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
myWindow.document.write("<br/>");
myWindow.document.write("<input type='text' id='txtId' />");
myWindow.document.write("<input type='button' value='Copy'/>");
var x = localStorage.getItem(Name);
}
myWindow.opener.document.write("Landed to prent");
}
I want my parent window to have button that opens child window. Child window should have an input text box and a button(Named Copy). Whatever i enter text in child window textbox and click Copy button, the child window should close and entered name should appear on parent window.
I am trying below approach but can't understand how to retrieve enter value on parent.
p>Click the button to create a window and then display the entered name on parent window.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var myWindow = window.open("", "MsgWindow", "width=200,height=200");
myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
myWindow.document.write("<br/>");
myWindow.document.write("<input type='text' id='txtId' />");
myWindow.document.write("<input type='button' value='Copy'/>");
var x = localStorage.getItem(Name);
}
myWindow.opener.document.write("Landed to prent");
}
Share
Improve this question
edited Oct 18, 2016 at 6:45
inaya
asked Oct 17, 2016 at 7:27
inayainaya
971 gold badge2 silver badges8 bronze badges
3
-
Not sure but you can try
window.parent
or window.top – Rajesh Commented Oct 17, 2016 at 7:35 - 1 Possible duplicate of Communication between tabs or windows – Pablo Lozano Commented Oct 17, 2016 at 7:55
- I am not sure with syntax. can u please provide additional details – inaya Commented Oct 17, 2016 at 9:35
1 Answer
Reset to default 6Initially my approach was incorrect is i was trying to access child window textBox from parent window whereas i should be doing reverse. Below is the working code.
Parent Window
<!DOCTYPE html>
<html>
<body>
<input type="text" id="txtName" readonly="readonly" />
<button onclick="myFunction()">Open</button>
<script>
function myFunction() {
var win = window.open("ChildWin.htm", "_blank", "width=200,height=200");
}
</script>
</body>
</html>
Child Window
<!DOCTYPE html>
<html>
<body>
<p>Enter name </p>
<input type="text" id="txtbx" />
<br/><br/>
<button onclick="copyFunc()">Copy</button>
<script>
function copyFunc() {
if (window.opener != null && !window.opener.closed) {
var txtName = window.opener.document.getElementById("txtName");
txtName.value = document.getElementById("txtbx").value;
}
window.close();
}
</script>
</body>
</html>
本文标签:
版权声明:本文标题:window.open - How to return data from child to parent window using javascript without using sessionStorage - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742048804a2417951.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论