Page 1 of 2
Changing frame from one frame to another
Posted: Thu Mar 24, 2005 8:04 am
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?
Posted: Thu Mar 24, 2005 8:09 am
by AGISB
I think you will need a javascript solution.
Posted: Thu Mar 24, 2005 8:22 am
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>
?
Posted: Thu Mar 24, 2005 8:45 am
by feyd
onclick can be utilized. Is the resulting page in the bottom frame dependant on what the top frame reloads to?
Posted: Thu Mar 24, 2005 9:03 am
by s.dot
No, it is not.
It will be the result of a query to select a random URL from a database.
Posted: Thu Mar 24, 2005 9:17 am
by feyd
here's the idea then:
Code: Select all
<a href="e;topframe.php?foo=bar"e; onclick="e;return jumpPage(3);"e;>foo me</a>
Code: Select all
var urls = ї 'someurl.php?var=hi', 'someurl.php?var=goodbye', 'other.php?bar=foo', 'another.php?page=12 ];
function jumpPage( i )
{
if( i < urls.length && i >= 0 )
{
var url = urlsї i ];
var bottomFrame = top.framesї1];
bottomFrame.location.href = url;
return true;
}
return false;
}
...
Posted: Thu Mar 24, 2005 9:24 am
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.
Posted: Thu Mar 24, 2005 9:28 am
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.
Posted: Thu Mar 24, 2005 10:02 am
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
that?
Posted: Thu Mar 24, 2005 10:05 am
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.
Posted: Thu Mar 24, 2005 11:11 am
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

Posted: Thu Mar 24, 2005 11:16 am
by feyd
similarly.. except there's no onclick event.
Posted: Thu Mar 24, 2005 1:20 pm
by s.dot
Thanks, works perfectly.

Posted: Wed Mar 30, 2005 11:51 pm
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 = ї '<? echo $sitesarrayї'url']; ?>' ];
function jumpPage( i ){
if( i < urls.length && i >= 0 ) {
var url = urlsї i ];
var bottomFrame = top.framesї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.
Posted: Thu Mar 31, 2005 12:15 am
by infolock
i would recommend you look into using
iFrames