Frames, menus and sessions - almost works!
Posted: Tue Mar 01, 2005 4:39 am
I am building a website based on two frames, topFrame and mainFrame. The topFrame contains the menu which is a simple table with links. I want to disable the link after the user clicks on it. Clicking on a subsequent menu link would disable the current link (the one just clicked) and also enable the previously disabled link. I've done this very thing in a simple one page format with the same table type structure and it works nicely although the menu scrolls off the page, hence the reason I want to use frames on this site.
Now, to combat the nastiness of frames I thought I would try using session variables to track what page the user was on. This works - sort of. The problem is that the enabling and disabling of the links doesn't happen unless I refresh the page.
I believe my problem has to do with timing. The menu being in topFrame is loading first and the session variable it needs gets set when the mainFrame is loaded. The menu displays properly when refreshed (or the same link is clicked again) because the session variable is set.
Must I put the menu at the bottom? Is there a way to force the mainFrame to load first? Is there another way to do this without using client side scripting?
Thanks for your help!
Jim
Here are some code snippits:
This builds the menu:
This is the header. I added some cache control because I thought it might be a caching issue:
This is a sample of the beginning of each content page:
Now, to combat the nastiness of frames I thought I would try using session variables to track what page the user was on. This works - sort of. The problem is that the enabling and disabling of the links doesn't happen unless I refresh the page.
I believe my problem has to do with timing. The menu being in topFrame is loading first and the session variable it needs gets set when the mainFrame is loaded. The menu displays properly when refreshed (or the same link is clicked again) because the session variable is set.
Must I put the menu at the bottom? Is there a way to force the mainFrame to load first? Is there another way to do this without using client side scripting?
Thanks for your help!
Jim
Here are some code snippits:
This builds the menu:
Code: Select all
function menu() {
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100">
<img src="images/logo2.jpg" border="0" height="100" width="92" alt="Logo">
</td>
<td width="*" align="center" valign="top">
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<?php
$links = array(
'index.html', 'Newsletter', 'index.html', 'Calendar',
'index.html', 'Education', 'index.html', 'Resources',
'main.php', 'Home', 'index.html', 'Membership',
'index.html', 'Gallery', 'about.php', 'About US',
'index.html', 'Contact Us', 'index.html', 'Login');
$c = 0;
while($c < count($links)) {
if($linksї$c+1] != $_SESSIONї'page']) {
echo '<td align="center">
<a href="' . $linksї$c] . '" target="mainFrame"
onClick="parent.framesї''topFrame''].location.reload()">'
. $linksї$c+1] . '</a></td>';
}else {
echo '<td class="selected" align="center">' .
$linksї$c+1] . '</td>';
}
$c = $c+2;
if($c == 10) echo '</tr><tr>';
}
?>
</tr>
</table>
</td>
</tr>
</table>
<hr>
<?php
}Code: Select all
function output_html_header($title, $style) {
?>
<html>
<head>
<LINK HREF="../public_html/styles.css" TYPE="text/css"
REL="stylesheet" TITLE="styles">
<?php output_html_title($title); ?>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<meta http-equiv="Cache-Control" Content="no-cache">
<meta http-equiv="Pragma" Content="no-cache">
<meta http-equiv="Expires" Content="0">
</head>
<body class="<?php echo $style; ?>">
<?php
}Code: Select all
<?php
session_start(); // for session support
$_SESSIONї'page'] = 'About Us'; // this is a marker for the page
include_once('../includes/includes.php');
output_html_header('Welcome to the Alliance', 'body');
?>