开发者

HTML + Passing Param b/w Parent & Child

开发者 https://www.devze.com 2022-12-12 12:44 出处:网络
It might be a simple, but the funny thing is 开发者_Python百科i\'ve tried it for almost 2-3hrs and haven\'t been able to solve it :(.

It might be a simple, but the funny thing is 开发者_Python百科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.


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消