View Full Version : OnLoad condition based on web address

08-08-2008, 08:12 PM
I am using an expandable and collapseable menu on my site. In the body tag I can use the OnLoad command to tell the menu which category I would like open. However, I am using the same menu on multiple pages and want the OnLoad to be dynamic based on what the web address is. I can't put the OnLoad on each page becuase those pages are dynamic as well and one file can be many different pages. Is there a way to set a function based on what the web address is and then use that in that function in the OnLoad.

I was told to maybe try this:

$page = $_SERVER['PHP_SELF'];
if ($page = index.php) {
if ($page = contact.php) {

Would that work and then if it does what would I put in the OnLoad command?



Is correct?

08-08-2008, 08:59 PM
It depends on what language you want to use because the one you posted was PHP and this is the Javascript forum, so which language would you prefer to use?

Philip M
08-09-2008, 10:17 AM
In principle:-

<script type = "text/javascript">
var winloc = window.location.href;
if (winloc == "index.php") {
do this (menu A)
else {
dothat (menu B)