demarcy
asked on
Opening a window with dependent=1 doesn't work
Hi all...
According to a Javascript manual I have, I can use the command dependent=1 when calling the window.open( ) method to cause the new window to be a child of the window who called that method... the problem is that I want to modify a value of an object of the parent window, but that object isn't found. Another fact.. if a window is opened with dependent=1 it should close when the parent close, but it doesn't work either..
Any help will be greatly appreciated
Demarcy
According to a Javascript manual I have, I can use the command dependent=1 when calling the window.open( ) method to cause the new window to be a child of the window who called that method... the problem is that I want to modify a value of an object of the parent window, but that object isn't found. Another fact.. if a window is opened with dependent=1 it should close when the parent close, but it doesn't work either..
Any help will be greatly appreciated
Demarcy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you have a java script object MyObject you can call a fn or change a variable in the object of the opener from the child window by calling
window.opener.myObj.name = "Child name";
Here's all the code
Parent.htm
_____________
<HTML>
<HEAD>
<script>
function myObject(name){
this.name = name;
}
</script>
</HEAD>
<BODY>
This is the parent....
After the child is opened then click the button to see the value of the variable in the object
<form name="myForm">
<input type="text" name="myText" value = "this is text from the parent">
<input type="button" name="blag" value = "get value" onclick="document.myForm.m yText.valu e=myObj.na me;">
</form>
<script>
myObj = new myObject("parentname");
document.myForm.myText.val ue = myObj.name;
childWindow = window.open("child.htm");
</script>
</BODY>
</HTML>
Child.htm
___________
<HTML>
<HEAD>
</HEAD>
<BODY>
This is the child window
<script>
window.opener.myObj.name = "Child name";
</script>
</BODY>
</HTML>
window.opener.myObj.name = "Child name";
Here's all the code
Parent.htm
_____________
<HTML>
<HEAD>
<script>
function myObject(name){
this.name = name;
}
</script>
</HEAD>
<BODY>
This is the parent....
After the child is opened then click the button to see the value of the variable in the object
<form name="myForm">
<input type="text" name="myText" value = "this is text from the parent">
<input type="button" name="blag" value = "get value" onclick="document.myForm.m
</form>
<script>
myObj = new myObject("parentname");
document.myForm.myText.val
childWindow = window.open("child.htm");
</script>
</BODY>
</HTML>
Child.htm
___________
<HTML>
<HEAD>
</HEAD>
<BODY>
This is the child window
<script>
window.opener.myObj.name = "Child name";
</script>
</BODY>
</HTML>
dependent is not a valid variable in the window.open function. To achieve what you want however, you need to do something like:
to open:
mychildwindow = window.open(...)
to close:
mychildwindow.close();
to pass values to the parent:
window.opener.etcetc
(with etcetc being the object you want to refer to)
this isn't as long as i wrote it before, but hope it helps,
regards,CJ