问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/17559050/how-to-pass-data-from-parent-html-window-to-pop-up-window