最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pass data from Parent html window to pop-up window - Stack Overflow

programmeradmin1浏览0评论

I am trying to pass some data from parent window to pop up window in html.

Below is my code-

<html>
<head>
<script type="text/javascript">
function init()
{
    popupWin = window.open('','popupWin','');
    popupWin.document.writeln('<html><head><title>test</title></head><body><form><input type="text" id="popupTextBox"/></form></body></html>');
    popupWin.document.close();
    popupText = popupWin.document.getElementById("popupTextBox");
    parentText = document.getElementById("parentTextBox");
}
function transferText()
{
    popupText.value = parentText.value
}
</script>
</head>
<body>
<input type="text" id="parentTextBox"/>
<input type="button" onclick="init();"/>
</body>
</html>

But somehow I am not able to pass that textbox data to popup window with the above code. Is there any problem with this?

In general, I am trying to pass some data from parent window to popup window.

I am trying to pass some data from parent window to pop up window in html.

Below is my code-

<html>
<head>
<script type="text/javascript">
function init()
{
    popupWin = window.open('','popupWin','');
    popupWin.document.writeln('<html><head><title>test</title></head><body><form><input type="text" id="popupTextBox"/></form></body></html>');
    popupWin.document.close();
    popupText = popupWin.document.getElementById("popupTextBox");
    parentText = document.getElementById("parentTextBox");
}
function transferText()
{
    popupText.value = parentText.value
}
</script>
</head>
<body>
<input type="text" id="parentTextBox"/>
<input type="button" onclick="init();"/>
</body>
</html>

But somehow I am not able to pass that textbox data to popup window with the above code. Is there any problem with this?

In general, I am trying to pass some data from parent window to popup window.

Share Improve this question asked Jul 9, 2013 at 22:01 arsenalarsenal 24.2k91 gold badges230 silver badges334 bronze badges 1
  • This might help stackoverflow./questions/5187510/… – Seano666 Commented Jul 9, 2013 at 22:08
Add a ment  | 

1 Answer 1

Reset to default 3

You forgot to call transferText()
After calling transferText() the text was transferred...

<html>
<head>
<script type="text/javascript">
function init()
{
    popupWin = window.open('','popupWin','');
    popupWin.document.writeln('<html><head><title>test</title></head><body><form><input type="text" id="popupTextBox"/></form></body></html>');
    popupWin.document.close();
    popupText = popupWin.document.getElementById("popupTextBox");
    parentText = document.getElementById("parentTextBox");
    transferText();
}
function transferText()
{
    popupText.value = parentText.value
}
</script>
</head>
<body>
<input type="text" id="parentTextBox"/>
<input type="button" onclick="init();"/>
</body>
</html>
发布评论

评论列表(0)

  1. 暂无评论