Categories:

Using JavaScript to load multiple frames

So what good is it to cross-access objects, you ask? Well, one of the most popular uses of such is to load and change the content of more than one frame at one. Without JavaScript, there isn't a prayer. Lets say we have the following example:

<html>
<frameset cols="30%,70%">
<frame src="page1.htm" name="frame1">
<frame src="page2.htm" name="frame2">
</frameset>
</html>

We want to add a link in the first frame (page1.htm is in it) that will change the contents of not only page1, but page2 too. Ok, here we go: The below is the html file for page1:

//page1.htm
<html>
<body>
<h1>This is page 1 </h1>
<a href="3.htm" onClick="parent.frame2.location='4.htm'">Click Here</a>
</body>
</html>

As you can see, this additional code will cause one link to perform two loading of pages.

Just for the hell of it, lets write a function that'll load 5 frames at once:

<script type="text/javascript">
function muchoframes(){
parent.frame1.location='6.htm
parent.frame2.location='7.htm
parent.frame3.location='8.htm
parent.frame4.location='9.htm
parent.frame5.location='10.htm
}
</script>

Nothing can stop you now!