Changing frame from one frame to another

JavaScript and client side scripting.

Moderator: General Moderators

User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Changing frame from one frame to another

Post by s.dot »

I have a script where there are two frames

top, and bottom for example.

What I need to do is after a link is clicked in the top frame, the top frame runs it's script, essentially submitting data and reloading itself, and then have the bottom frame change to a different page.

I know a simple target="" is what some of you will say, but I need the top frame to reload itself and run, and the bottom frame to change at the same time. How can I go about doing this?
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

I think you will need a javascript solution.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

will an OnClick event handler be a possible solustion?

Like <a href="reloadthisframe.php?var=string" onClick="something I don't know here">Click</a>

?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

onclick can be utilized. Is the resulting page in the bottom frame dependant on what the top frame reloads to?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

No, it is not.

It will be the result of a query to select a random URL from a database.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

here's the idea then:

Code: Select all

&lt;a href=&quote;topframe.php?foo=bar&quote; onclick=&quote;return jumpPage(3);&quote;&gt;foo me&lt;/a&gt;

Code: Select all

var urls = &#1111; 'someurl.php?var=hi', 'someurl.php?var=goodbye', 'other.php?bar=foo', 'another.php?page=12 ];
function jumpPage( i )
{
  if( i &lt; urls.length &amp;&amp; i &gt;= 0 )
  {
    var url = urls&#1111; i ];
    var bottomFrame = top.frames&#1111;1];
    bottomFrame.location.href = url;
    return true;
  }
  return false;
}
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

...

Post by s.dot »

Actually, after reviewing my coding, it would be dependant on the top frame. Because I would have to update records in the database on the random URL chosen. Then I would need to have it load in the bottom frame.

Sorry for not clarifying this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

okay.. so basically, you'll need an onload handler for the top frame which will do the url change to the bottom frame after the top frame loads again.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

something like...

Code: Select all

function newpage(){
$sitearray = mysql_fetch_array(mysql_query("SELECT url FROM sites WHERE activated = 'y' ORDER BY rand() LIMIT 1")); }
Then the onload in the top frame

Code: Select all

<body onLoad="<? newpage(); ?>">
that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no. It doesn't involve any php other that to dynamically change/write the url to send the bottom frame to. It's all Javascript.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

feyd wrote:no. It doesn't involve any php other that to dynamically change/write the url to send the bottom frame to. It's all Javascript.
do this by using the code that you posted above :?:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

similarly.. except there's no onclick event.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Thanks, works perfectly. :)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I used this code to generate a random URL to a bottom frame, once a top frame was reloaded.

Code: Select all

<script>
var urls = &#1111; '<? echo $sitesarray&#1111;'url']; ?>' ];
function jumpPage( i ){
	if( i < urls.length && i >= 0 )  {
	var url = urls&#1111; i ];
	var bottomFrame = top.frames&#1111;1];
	bottomFrame.location.href = url;
	return true;  }
return false; }
</script>
It works good. My question is, how can I generate a text link in my top frame, that when clicked opens this link in a new window. I don't know how to return the value of the URL generated. <a href="location.href(top.frames[1]" target="_blank"> I tried that, but to no avail.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i would recommend you look into using iFrames
Post Reply