English 中文(简体)
HTML + Passing Param b/w Parent & Child
原标题:

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.

最佳回答

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>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签