Click to See Complete Forum and Search --> : Is it possible
2muchtime
02-18-2003, 03:13 AM
Ok, I will try to explain this as best I can, and hope that somebody can help me.
I have a navigation bar that runs across the topof my page, and I would like to set it up so that it is written to the page by an external javascript. I am doing this because I have about 15 different pages to update everytime something changes, so If it is possible to write the nav from n external source. If it can't be done with javascrit what can it be done with?
Charles
02-18-2003, 04:37 AM
Keep in mind that JavaScript will fail for at least one in ten users and some of those users cannot use JavaScript because of their disabilities. It is very bad to rely upon JavaScript for navigation and in some places for some web sites it is illegal.
The best method is some kind of server side include. Talk to your server people.
The second best is to properly use the IFRAME element providing a link to the menu for browsers that do not support the IFRAME element. <iframe src="http://www.w3.org/><a href="http://www.w3c.org/>W3C</a></iframe>
The worst method is to use JavaScript, for you will have to create two files, one full of document.write calls and one HTML version of the menu that you can provide a link to in the NOSCRIPT element.
2muchtime
02-18-2003, 05:19 PM
I would use iframes, but they aren't very well supported by older browsers. I am still trying tomaintain compatibility so If javscript won't do it what other language will?per? I am venturing to learn perl, but I think it will take a while, and javascript seems like the best solution. My question though, mainly had to do with code. I have written the script, but when I try to have an external file write anything to the page it doesn't work.
Nedals
02-18-2003, 05:50 PM
Another method would be to use frames (assumes the header of each page is the same). If you DO use Javascript, also supply a link to a simple site map for navigation.
Lastly, if you need help with a script that does not work, it really helps if you post the script OR a link
AdamBrill
02-18-2003, 05:55 PM
Here is the PHP code to do that:
<?PHP
$filename="Data.dat";
$fp=file($filename);
$x=0;
$code="";
do
{
$code.=$fp[$x];
$x++;
} while($fp[$x]);
echo $code;
?>
Just change the $filename to the name of the file that you want to open. It will open the file and write all of the contents onto your page. Make sure that you rename your file from whatever.htm to whatever.php. If the file extenstion isn't .php, it won't work. I hope this helps...
Nedals
02-18-2003, 07:08 PM
Adam, I'm a long time perl user and it's about time I became familiar with PHP. I have a couple of questions about the code you posted, so I added some comments to your code. I would go to another section, but there's no PHP.
<?PHP
$filename="Data.dat";
$fp=file($filename);
$x=0;
$code="";
do
{
$code.=$fp[$x]; //gets each line from the file???
$x++;
} while($fp[$x]);
echo $code; // Writes to browser. Can this be done inside the loop
?>
For this application, should he use...
<?PHP
// I don't know the 'comment' syntax.
// messed with your code a bit and could be wrong!!!
// Output the header
$filename="Header.dat";
$fp=file($filename);
$x=0;
do
{
echo $fp[$x];
$x++;
} while($fp[$x]);
// Do I need to close the file??
// Output the content
$filename="Content.dat";
$fp=file($filename);
$x=0;
do
{
echo $fp[$x];
$x++;
} while($fp[$x]);
?>
AdamBrill
02-18-2003, 07:31 PM
nedals-Your comments on my code are correct. And this code here:
<?PHP
// I don't know the 'comment' syntax.
// messed with your code a bit and could be wrong!!!
// Output the header
$filename="Header.dat";
$fp=file($filename);
$x=0;
do
{
echo $fp[$x];
$x++;
} while($fp[$x]);
// Do I need to close the file??
// Output the content
$filename="Content.dat";
$fp=file($filename);
$x=0;
do
{
echo $fp[$x];
$x++;
} while($fp[$x]);
?>
would basically do the same thing. The file($filename) line does not have to be closed, but if you would do it like this:
$fp = fopen($filename, "r");
then you would have to close it like this:
fclose($fp);
I prefer to use the file() function, but that is up to the programmer. They are used slightly differently in the code, too. The code that you posted would work fine also; the only difference between yours and mine is that I used a variable and you didn't. It will function exactly the same. The other thing is your code reads Header.dat and Content.dat, which I assume you already knew.
And, just so you know, there is an excellent php forums located here: http://www.phpbuilder.com/board/ I hope all of this helped...