?
Solved

Opening a window with dependent=1 doesn't work

Posted on 2000-05-15
3
Medium Priority
?
200 Views
Last Modified: 2008-03-03
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
0
Comment
Question by:demarcy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 2810834
dammit, I lost everything I wrote here. Here goes again

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

Accepted Solution

by:
lilian_kelly earned 200 total points
ID: 2810842
dependent will only work in  Navigator 4 and it should be set to yes or no. Its yes by default.


Here is some code that will open a child window. The child window will change the value of the text box in the parent and then if you click the close button on the parent then the child window will close. It works for both IE and Netscape.

When you say object do you mean a java script object? I will try this out next. But in the mean time this may help.

parent.htm
______________________________________

<HTML>
<HEAD>

</HEAD>

<BODY>
This is the parent....
<form name="myForm">
      <input type="text" name="myText" value = "this is text from the parent">
      <input type="button" name="closechild" value = "closechild" onclick="childWindow.close();">
</form>
<script>
alert("about to open a child window and let it set the value of the text box..");
childWindow = window.open("child.htm");
</script>
</BODY>
</HTML>

______________________________________
child.htm
_______________________________________


<HTML>
<HEAD>

</HEAD>

<BODY>
This is the child window
<script>
window.opener.document.myForm.myText.value = "Child has set this value";
</script>
</BODY>
</HTML>


0
 
LVL 2

Expert Comment

by:lilian_kelly
ID: 2810895
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.myText.value=myObj.name;">
</form>
<script>

myObj = new myObject("parentname");
document.myForm.myText.value = 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>
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question