Javascript HTML+;通过参数b/w父级和;小孩
这可能是一个简单的问题,但有趣的是,我已经尝试了将近2-3个小时,但仍然无法解决它:( 我有一个父窗口,它有一个文本框,它有一个值。我有一个窗口。打开并打开一个客户端,尝试读取父窗口的值,但无法获取值 任何帮助 我试过了Javascript HTML+;通过参数b/w父级和;小孩,javascript,html,parent-child,Javascript,Html,Parent Child,这可能是一个简单的问题,但有趣的是,我已经尝试了将近2-3个小时,但仍然无法解决它:( 我有一个父窗口,它有一个文本框,它有一个值。我有一个窗口。打开并打开一个客户端,尝试读取父窗口的值,但无法获取值 任何帮助 我试过了 window.parent.document.getElementById(window.name) window.parent.document.getElementById('test').value window.opener.document.getElementByI
window.parent.document.getElementById(window.name)
window.parent.document.getElementById('test').value
window.opener.document.getElementById('teast')。value
window.parent.opener.document.getElementById('teast')。value
window.opener.parent.document.getElementById('teast')。value
几乎所有的排列和组合。以及它的纯HTML。
window.opener.document.getElementById('test')。value
应该都能用。我试过了,没用。我正在发布代码
test.html
聊天
var newWin=null;
var OpenWindow=null;
函数弹出窗口(strURL、strType、streight、strWidth){
if(newWin!=null&&!newWin.closed)
newWin.close();
var strOptions=“”;
如果(strType==“控制台”)
strOptions=“可调整大小,高度=“+
strHeight+”,width=“+strWidth;
如果(strType==“固定”)
strOptions=“status,height=“+
strHeight+”,width=“+strWidth;
if(标准类型==“弹性”)
strOptions=“工具栏、菜单栏、滚动条,”+
“可调整大小,位置,高度=“+
strHeight+”,width=“+strWidth;
警报(window.parent.document.getElementById(window.name));
newWin=window.open(strURL,'alertWindow',strOptions);
//newWin.document.getElementById(“child”).value='Str';
newWin.focus();
//发送_数据(数据);
}
函数chat(){
弹出窗口(“../alert.jsp”,“控制台”,250600);
}
child.html
警觉的
函数加载(){
警报(“装载中”);
警报(“001=“+window.parent.document.getElementById('teast'));
警报(“002=“+window.parent.document.getElementById(window.name));
警报(“003=“+window.opener.document.getElementById('teast').value”);
}
由于安全限制,Javascript无法访问位于与当前域不同的域中的文档。因此,如果您的父域与子域位于不同的域中,这将永远无法工作。页面是否来自同一域?Josh,文件位于同一域中!不知道我做错了什么:(
<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>
<!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>