Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Object between Frames

Status
Not open for further replies.

Draug

Programmer
Apr 18, 2001
77
CA
Greetings,

There are two frames, and one included JavaScript file.

The file contains:
- an object definition
- methods for that object

Frame 1 contains:
- the javascript file is included in this frame like so:
<script language=&quot;javascript&quot; src=&quot;myfile.js&quot;></script>
- the object is instantiated in Frame 1 like so:
var alex = new HumanBeing();
- all of my methods and attributes of HumanBeing are accessed in this frame as normal.

Frame 2:
- I want to use and manipulate the same object in this frame.


How can I do this? I thought parent.Frame1.alex would give me access to the object but it does not. I have tried many variations of that since, but cant get any og them to work.

Any ideas?

Thank you,
Jason
 
hi, you must have in attencion that you have to pass the object to a container or pass directly to the frame.

the rest of the functions that access to the object, must contain the &quot;parent.main&quot; - assuming that &quot;main&quot; is the name of the frame. - must have the direction of the frame.

Example:
/////// functions in the header frame
function Alerta(el){
alert(el);
}


function Create_Div(){
parent.main.document.write(&quot;<div id='test1' style='background-color:red' onclick='parent.header.Alerta(this.id)'> Test </div>&quot;)
}
///////******


//in the above function(Create_Div()) we create a div in the parent frame, notice that i wrote [parent.main.document.write(&quot;<div...]. informing the system that it will wrote in the parent frame name.

// in the div, i'm saiyng the on clicking it will return a function that is in the &quot;header&quot; frame [onclick='parent.header.Alerta(this.id)'], by applying this method all your functions will be in the header frame and they can be accessed from the main frame


Best Regard's
Vegeta
(Please vote for the script)
 
Thanks Vegata,

That seems to work if I have the functions declared in the actual frame. However, if I include a Javascript file into one of the frames, I cant seem to access the functions in the included file from another frame.

Jason
 
Hi,

I figured it out. I had my include after the the Frameset had been defined. No wonder I could not reference the file from the frames. Chalk that one up to stupid mistake!


Thanks alot for your help,
Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top