2013-07-09 47 views
2

我试图从父窗口传递一些数据以在HTML中弹出窗口。如何将数据从父窗口传递到弹出窗口

下面是我的代码 -

<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> 

但不知何故,我不能来传递文本数据与上面的代码来弹出窗口。这有什么问题吗?

一般来说,我试图将一些数据从父窗口传递到弹出窗口。

+0

这可能有助于http://stackoverflow.com/questions/5187510/how-can-a-javascript- parent-window-send-data-to-popup-window – Seano666

回答

2

你忘了打电话给transferText()
调用transferText()文本转移后...

<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> 
+1

调用方法的实际流程是什么?你能提供完整的语法代码吗?谢谢 – ferhan

+0

(我将我的代码添加到答案中) –

+2

有什么办法可以做相反的事吗?将数据从弹出窗口传递到父窗口? –

相关问题