Page 1 of 1
frames and $_GET
Posted: Thu Oct 06, 2005 4:26 pm
by s.dot
Firstly, I don't know whether this belongs here or in Client Side.
I have a framepage that loads two basic frames. A top frame, and a bottom frame. What I'm wanting to do is have the bottom page stay the same, but the user should be able to navigate in the top frame. It works good except when a link in the top page uses $_GET.. such as they click on a link like page.php?foo=bar.. it then breaks my page out of frames and loads that page as the whole page.
I expected this.. because it has to know the URL in order to execute the PHP.. but is there any way around this? Is it possible to do?
Posted: Thu Oct 06, 2005 4:30 pm
by Burrito
Moved to client side
use the target attribute of your anchor tag....
Posted: Thu Oct 06, 2005 4:37 pm
by s.dot
the bottom frame doesn't have any links... just the links in the top frame.. and i want them to open in the top frame.. not another 'target' frame.. if you know what I mean
Posted: Thu Oct 06, 2005 4:41 pm
by Burrito
so give your frame an id and a name and then use the target attribute to tell it where to open the page:
ex:
Code: Select all
<a href="whatever.php" target="topFrame">whatever</a>
Posted: Thu Oct 06, 2005 4:53 pm
by s.dot
whoa.. I thought you were way off base with your answer.. and didn't understand my question.. but it worked beautifullly

congrats to you burrito man!
Now, on to a tougher question.. sometimes the top frame will be in a framed page, and other times it will be on a page by itself ( the user has the option to choose frames, or just view the top page of the frames in a page of its own)
Now, I'd hate to go through my WHOLE site, giving every link a target attribute.. that would be hard.. and very time consuming.
Is there a piece of code I can write.. or something.. that can check to see if there is frames, then if there is, give all A tags, a target attribute..
or would I have to do that manually?
Posted: Thu Oct 06, 2005 5:11 pm
by Burrito
here's what I'd do:
I'd create a "preferences" section that allows the user to choose whether they want frames or not then store that preference in a session var.
you could then do an extended find and replace for all of your <a> tags and add something like this:
Code: Select all
<a href="blah.php" <?php echo ($_SESSION['frames'] == 'yes' ? "target=\"topFrame\"" : "");?>>link</a>
Posted: Thu Oct 06, 2005 5:20 pm
by s.dot
okay.. well I basically gave you a general scenario earlier.. so here's the real situation.
I'm implementing a 'chatbar' feature of my website.. for users who want to chat and browse the site at the same time. when they go to the frame page (chatbar.html) the top frame is the rest of the site, and the bottom page is the chat.. so they can chat and browse at the same time.. so I don't really think a session would be fit because it's not really their 'preference' so to speak..
I guess when they load chatbar.html I could update a field in my database that would tell the php page it's using frames.. then how would I do the find and replace on a whole page, without manually editing each link?
What about CSS, can you give links a target in the css?
Posted: Thu Oct 06, 2005 6:07 pm
by Luke
scrotaye wrote:What about CSS, can you give links a target in the css?
I'm going to say with 95% certainty that you can not.
Posted: Thu Oct 06, 2005 6:12 pm
by Burrito
I'll add the other 5%
you could use your flagged field on the db idea and if it's flagged, then do what I posted above to "inject" the target into the links.
Posted: Thu Oct 06, 2005 8:35 pm
by s.dot
Code: Select all
<a href="blah.php" <?php echo ($_SESSION['frames'] == 'yes' ? "target=\"topFrame\"" : "");?>>link</a>
I'll be blunt.. what exactly does this do? how do I use it, and where do I put it? =/ I've never used something like this in my code. Would someone please explain it to me

Posted: Thu Oct 06, 2005 8:41 pm
by Burrito
it's the ternary operator:
go
here and look about a sixth of the way down the page for "Ternary Operator".
Basically it's an if / else but much more concise.
in the case that I wrote it would compare to this:
Code: Select all
if($_SESSION['frames'] == "yes")
echo "target=\"topFrame\"";
else
echo "";
Posted: Thu Oct 06, 2005 8:45 pm
by s.dot
ah, understood.
so i'd have to place this code manually into all of the link tags?
Posted: Thu Oct 06, 2005 8:47 pm
by Burrito
or do as I suggested and do an extended find and replace to do it...if your editor doesn't have an extended find and replace...you need a new editor

Posted: Thu Oct 06, 2005 8:52 pm
by s.dot
I could do that.. but not all links look the same.. I guess I could do
Code: Select all
<a <? insert your ternary operator here ?> href="blah.php">link</a>
a bit backwards from how I usually do things, but it should work.
Posted: Fri Oct 07, 2005 1:19 am
by n00b Saibot
you can add the target attribute to the links on the fly using DOM
