HTML +传递参数 b/w Parent &孩子

发布于 2024-08-12 04:13:23 字数 577 浏览 7 评论 0原文

这可能很简单,但有趣的是我已经尝试了近 2-3 小时但无法解决它:(。

我有一个父窗口,其中有一个文本框,并且它有一个值。我做了一个 window.open 并打开一个客户端并尝试读取父项的值,但无法获取该值

)

我尝试过

  1. window.parent.document.getElementById(window.name )
  2. window.parent.document.getElementById('test').value
  3. window.opener.document.getElementById('teast').value
  4. window.parent.opener.document.getElementById('teast').value
  5. window.opener.parent.document.getElementById('teast').value

几乎所有的排列组合。而且是纯 HTML。

It might be a simple, but the funny thing is i've tried it for almost 2-3hrs and haven't been able to solve it :(.

I have a parent window, which has a text box, and it has a value. I do a window.open and open a client and try to read the value of the parent, but unable to get the value.

Any help!!

I've tried

  1. window.parent.document.getElementById(window.name)
  2. window.parent.document.getElementById('test').value
  3. window.opener.document.getElementById('teast').value
  4. window.parent.opener.document.getElementById('teast').value
  5. window.opener.parent.document.getElementById('teast').value

Almost all the permutation and combination. And its pure HTML.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁把谁当真 2024-08-19 04:13:23

由于安全限制,Javascript 无法访问驻留在与当前域不同的域中的文档。因此,如果您的父母与孩子位于不同的域中,则这将永远起作用。

Due to security restrictions, Javascript is unable to access documents that reside on a separate domain from the current one. So, if your parent is on a different domain from the child, this will never work.

下壹個目標 2024-08-19 04:13:23

window.opener.document.getElementById('test').value 应该可以工作。

window.opener.document.getElementById('test').value should work.

木森分化 2024-08-19 04:13:23

我已经尝试过,它不起作用。我发布代码

test.html

<html>
<head>
<title>Chat</title>
</head>
<body>

<div id="chatMessages"></div>
<script>

var newWin = null;  
var OpenWindow = null;
function popUp(strURL, strType, strHeight, strWidth) {  
 if (newWin != null && !newWin.closed)  
   newWin.close();  
 var strOptions="";  
 if (strType=="console")  
   strOptions="resizable,height="+  
     strHeight+",width="+strWidth;  
 if (strType=="fixed")  
   strOptions="status,height="+  
     strHeight+",width="+strWidth;  
 if (strType=="elastic")  
   strOptions="toolbar,menubar,scrollbars,"+  
     "resizable,location,height="+  
     strHeight+",width="+strWidth;
 alert(window.parent.document.getElementById(window.name));
 newWin = window.open(strURL, 'alertWindow', strOptions);

 //newWin.document.getElementById("child").value='Str';  
newWin.focus();  
// send_data(data);
}


function chat() {
    popUp('../alert.jsp','console',250,600);
}

</script>

<form name="AlertReceiverOnHeader" onclick="chat()">
<input type="text" value="teast" id="teast" name="teast"/>
</form>

</html>

child.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Alert</title>
</head>
<body onload="load()">


<script language="JavaScript">

function load() {
    alert('In load');
    alert("001="+window.parent.document.getElementById('teast'));
    alert("002="+window.parent.document.getElementById(window.name));
    alert("003="+window.opener.document.getElementById('teast').value);

}
</script>

<form name="child">
<input type="text" id="child" value="child"/>
</form>
</body>
</html>

I've tried that, it ain't work. I'm posting the code

test.html

<html>
<head>
<title>Chat</title>
</head>
<body>

<div id="chatMessages"></div>
<script>

var newWin = null;  
var OpenWindow = null;
function popUp(strURL, strType, strHeight, strWidth) {  
 if (newWin != null && !newWin.closed)  
   newWin.close();  
 var strOptions="";  
 if (strType=="console")  
   strOptions="resizable,height="+  
     strHeight+",width="+strWidth;  
 if (strType=="fixed")  
   strOptions="status,height="+  
     strHeight+",width="+strWidth;  
 if (strType=="elastic")  
   strOptions="toolbar,menubar,scrollbars,"+  
     "resizable,location,height="+  
     strHeight+",width="+strWidth;
 alert(window.parent.document.getElementById(window.name));
 newWin = window.open(strURL, 'alertWindow', strOptions);

 //newWin.document.getElementById("child").value='Str';  
newWin.focus();  
// send_data(data);
}


function chat() {
    popUp('../alert.jsp','console',250,600);
}

</script>

<form name="AlertReceiverOnHeader" onclick="chat()">
<input type="text" value="teast" id="teast" name="teast"/>
</form>

</html>

child.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Alert</title>
</head>
<body onload="load()">


<script language="JavaScript">

function load() {
    alert('In load');
    alert("001="+window.parent.document.getElementById('teast'));
    alert("002="+window.parent.document.getElementById(window.name));
    alert("003="+window.opener.document.getElementById('teast').value);

}
</script>

<form name="child">
<input type="text" id="child" value="child"/>
</form>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文