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

access objects in one frame from another

Status
Not open for further replies.

aleahim

Programmer
Jun 3, 2002
22
0
0
RO
Hi,

This script seems to work but it gives me an error too:

First I wrote a two columns framed document:
<frameset cols=&quot;30%,70%&quot;>
<frame src=&quot;page1.html&quot; name=&quot;foody&quot;>
<frame src=&quot;page2.html&quot; name=&quot;goody&quot;>
</frameset>

page1.html:
<body>
<script language=&quot;JavaScript&quot;>
function testing()
{
var x = &quot;this is page1!&quot;;
alert(x);
}
</script>

<script language=&quot;JavaScript&quot;>
testing();
</script>
</body>

Page2:
<body>
<script language=&quot;JavaScript&quot;>
parent.foody.testing();
</script>
</body>

It work but I receive an error: &quot;parent.foody.testing is not a function&quot;.
Do you know why?

Many thanks
 
You can see the alert because this code
Code:
<script language=&quot;JavaScript&quot;>
testing();
</script>
is not included into a function so it's executed as soon as your page loads. In others words, your testing function is not called by page2 but by page1. To make it work on page2, try :
Code:
window.frames('foody').testing();

NOTE : scripts are usually placed in <head> rather than in <BODY>. Water is not bad as long as it stays out human body ;-)
 
Just a quickie, I had a feeling that when you call a function from another page, you have to leave off the (), or am I thinking of something else?
Anyway, try calling it without the () and see what happens.
e.g.
Code:
window.frames('foody').testing;
 
It doesn't work. I try with window.frames('foody').testing(); and with window.frames('foody').testing;

I receive the error: window.frames is not a function.
 
try &quot;window.parent.frames(&quot;foody&quot;).testing();&quot; or &quot;window.parent.frames(&quot;foody&quot;).testing;&quot; Water is not bad as long as it stays out human body ;-)
 
Well I always use (probably a good reason why I shouldn't though)
Code:
top.foody.testing;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top