Javascript and Dynamic Webpages
On my site at the moment I'm using a php script which dynamically includes a content file into my main file. You may have seen it on other sites. It usually looks something like index.php?action=blah. An example here.
The problem lies with the fact that all the content pages use the same body and head info. But most javascripts require that you insert code into the body and into the head of the document. But if all my content pages share the same document can it be done? Is there any way around this?
Thanks,
Nuke
Busy posted this at 22:42 — 6th August 2002.
He has: 6,151 posts
Joined: May 2001
If your using php you can include if statements in the head and/or body sections. you can write the script to the page or include a file with the script.
if ($action == 'blah'){ show this; }
if ($action == 'blahblah'){ show this instead; }
or can use if / elseif / else or switch.
I use this method on one of my sites, it has a side table section, about 8 pages are called to the main page depending on the link choosen and in each included file i have
$main_contents = (" all the main contents");
$side_contents = ("all the side contens");
so when the page is called the main_contents is displayed in the main section and side on the side ...
nuk3 posted this at 05:07 — 7th August 2002.
They have: 238 posts
Joined: May 2002
Thanks for your help, but I'm still having a few problems. Your way works but when I put code up the top in the head it displays it on my page. Is there anyway to keep it from not being displayed on the page?
Here is what I have:
<?php
<head>
<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/style.css\">
<title>Useful Ingredients</title>
if ($page == \"csslinks\") {
print (\"hello\");
}
</head>
?>
Is it because I'm using the print command? I have a hunch that it might be...
Busy posted this at 04:36 — 20th August 2002.
He has: 6,151 posts
Joined: May 2001
yep, the print command is causing it, do your if statements where you want the content
...
<?php
if ($page == "csslinks") {
print ("csslink javascript stuff or include a file");
}
?>
...
<?php
if ($page == "csslinks") {
print ("csslinks main section or include from file above or seperate file");
}
?>
...
nuk3 posted this at 10:39 — 27th August 2002.
They have: 238 posts
Joined: May 2002
Sorry for the late reply. Thanks for all your help
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.