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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting variables and using them between frames

Status
Not open for further replies.

istar5

Technical User
Aug 1, 2003
4
GB
I have seen plenty of threads on this sort of topic, but for some reason can't get any of the information in them to work for me :(

I have an index.htm frameset page with three frames (leftFrame, bottomFrame and mainFrame).

leftFrame is my main Navigation. bottomFrame is targetted by the leftFrame to show some thumnails.

I then want to be able to click each thumbnail to show a full-size version of the picture in mainFrame, and use the action of clicking the thumnail to set the size of the full-size picture (the full-size pics are of different sizes, so I can't just load the .jpgs).

I've tried playing about with onclicks in the <img> tags, forms, and various functions (eg targetframe.location.href=&quot;whatever.htm&quot; having set using variables for the picture name, width and height). For some reason I just can't get my head round it...

Can anyone help please!?!?!?
 
It is probably harder to explain that to demonstrate. If you post your FRAMESET page I can give an example.

Basically you need to go up to the common window and then delve into the frame to get the variable.

Something like:

var fetchVariable = parent.frameID.variable;
 
Thanks for replying so quick!

Do you mean post my index.htm frameset? Is so, here it is:

<html>
<head>
<title>Kif's Website</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<frameset cols=&quot;145,*&quot; frameborder=YES&quot; border=&quot;1&quot; framespacing=&quot;0&quot; rows=&quot;*&quot;>
<frameset rows=&quot;165,*&quot; frameborder=&quot;YES&quot; border=&quot;1&quot; framespacing=&quot;0&quot; cols=&quot;*&quot;>
<frame name=&quot;leftFrame&quot; scrolling=&quot;NO&quot; noresize src=&quot;Navbar.htm&quot;>
<frame name=&quot;bottomFrame&quot; scrolling=&quot;AUTO&quot; noresize src=&quot;Navbar2.htm&quot;>
</frameset>
<frame name=&quot;mainFrame&quot; src=&quot;Home.htm&quot;>
</frameset>
<noframes>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
</body>
</noframes>
</html>

The example you gave would presumably go inside the <SCRIPT> tags on the page in the mainFrame? Is that right?

Thanks!
 
Example:

I have a variable inside Navbar.htm

<SCRIPT>
var myName=&quot;stormbind&quot;;
</SCRIPT>

I want to call that variable from Home.htm

<body onload=&quot;alert(parent.leftFrame.myName);&quot;></body>

Alert! stormbind

parent : the framset (index.htm)
leftFrame: the ID= of the frame you want to contact
myName : a variable that exists in that frame

Note: For security reasons you cannot communicate across pages on different domains.

Also, if you have framsets inside framesets you will have have to keep going (to get to a common page) i.e. parent.parent.myPage.myVariable - not required on this occation.

Hope that answers your questions :)
 
This makes sense, and I've got it to work for a message in an onLoad, per your example but I can't reference the variable for an image with in the <body>:

<img src=parent.leftFrame.picture height=&quot;300&quot; width=&quot;400&quot;>

I think it's the syntax, but I've tried several variations and I can't get it to work - the image just isn't displayed.

Any ideas?
 
<SCRIPT>
document.write('<IMG SRC=&quot;'+parent.leftFrame.picture+'&quot;>');
</SCRIPT>
 
Bellow tells the browser to parse the contents for scripts. If you don't include these tags, nothing will be parsed.

<SCRIPT> ... </SCRIPT>

The following tells javascript to write .... to the page

document.write('....');

The following does exactly the same thing: + adds things together.

document.write('..'+'..');

Now we don't want Javascript writing the variable into the page, so we ommit the quotes as in the next example.

document.write(variableName);

Now stick all the above concepts to create the tiny script I posted in my previous post.

I hope this helps because there is nothing worse that staring at a script and not understanding what it does - especially if you need to ever edit it :)
 
The reason <SCRIPT> ... </SCRIPT> wasn't required in the earliest example is that onload= is a script firing event - these also tell the browser to parse for javascript :)

Some examples of popular firing events:

onload=&quot;....&quot;
onclick=&quot;....&quot;
onmouseover=&quot;....&quot;
 
Excellent - it works at last!

I think my main problem was mixing bits from too many types of approach (firing events, document.write etc) and not being too sure about the syntax anyway...

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top