我想将parent.php中的文本框值传递给我的弹出窗口(child_page.php)。以下是我的代码。 parent.php -
<html>
<head>
<script type="text/javascript">
var popupWindow=null;
function child_open()
{
popupWindow =window.open('child_page.php',"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");
}
function parent_disable() {
if(popupWindow && !popupWindow.closed)
popupWindow.focus();
}
</script>
<input type="text" name="myTextField" id="myTextField" required="required"/>
</head>
<body onFocus="parent_disable();" onclick="parent_disable();">
<a href="javascript:child_open()">Click me</a>
</body>
</html>
child_page.php
<h1>child page</h1>
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
var x=parent.document.getElementById('myTextField').value
<?php echo x; ?>
</script>
<?php
//how do I get the textbox value here.
?>
我用Google搜索并试图这样做。因为我对Java脚本知之甚少,所以无法将这些答案作为一种解决方案。
答案 0 :(得分:1)
你的html中有很多错误。在关闭head标记之前,您正在编写input元素。把它移到体内。并尝试这样的事情:
<html>
<head>
<script type="text/javascript">
var popupWindow=null;
function child_open(val){
popupWindow =window.open('child_page.php' + "?val=" + val,"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");
}
function parent_disable() {
if(popupWindow && !popupWindow.closed)
popupWindow.focus();
}
</script>
</head>
<body onFocus="parent_disable();" onclick="parent_disable();">
<input type="text" name="myTextField" id="myTextField" required="required"/>
<a href="#" onclick="var val = document.getElementById('myTextField').value; child_open(val);return false">Click me</a>
</body>
</html>
现在,在您的child_page.php
中,您可以使用$_GET['val']
获取价值。
//child_page.php
<h1>child page</h1>
<?php $x = $_GET['val']; ?>
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
</script>
<?php echo $x; ?>