dynamicly change page link?

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
mark1
Advanced
Advanced
Posts: 12
Joined: Fri Apr 01, 2005 2:32 pm

dynamicly change page link?

Post by mark1 »

I don't know if this is a javascript or php problem. I use templates creating these pages. I have a header menu file and a footer menu file. In my footer menus I want a link to the top of the page. I need to dynamicly set the page name and path. When I tried php the file name returned was the footer file name. Tried passing page name to the footer file but I could not figure it out.

JavaScript works but then I noticed a problem when the reload button was clicked. When reload is clicked the link has http://myurl.com/pagename.php#MAIN_TOP#MAIN_TOP

I am sure there is a better way I just don't know what it is and was hoping someone could help.

here is the code for the footer menu.

Code: Select all

<script type="text/javascript">
var this_page="";
this_page=document.URL;
this_page=this_page+"#MAIN_TOP";
     with(milonic=new menuname("Main Menu")){
      style=menuStyle;
      alwaysvisible=1;
      orientation="horizontal";
      overfilter="";
      overflow="scroll";
      position="relative";
       aI("text=Home;url=<?php echo HTTP_SERVER; ?>;");
       aI("text=The Top;url="+this_page+";");
       aI("text=Site Map;url=<?php echo HTTP_SERVER . "sitemap.php" ?>;");
       aI("text=Milonic Menus;url= http://milonic.com/;target=_blank;");
 }
    drawMenus();
</script>
Thanks for the help and the great menu system.
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Mark,

This may seem overly simplified, but how about an item like:

Code: Select all

aI("text=Top;url=#;");
I believe that should take you to the top of any page.

Cheers,

Kevin
User avatar
John
 Team
 Team
Posts: 5967
Joined: Sun May 19, 2002 8:23 pm
Location: Phoenix, AZ
Contact:

Post by John »

You can't have more than one set of "" in your aI statements...

Code: Select all

aI("text=The Top;url="+this_page+";");
Here you have two, which is messing up the aI.

You'll need to escape those buggers 'inside'. Try a \" , or just a single back-quote ( ` ) in place of the extra ".
John
mark1
Advanced
Advanced
Posts: 12
Joined: Fri Apr 01, 2005 2:32 pm

Post by mark1 »

Thanks for the replys I tried them and no luck. I did notice it only happens on IE using the original code. Saddly this is most of my audience.

Kevin this sent me to the top of the index page from any page.

Code: Select all

aI("text=Top;url=#;");
John I tried single quotes and backslash double quote and neither worked but the way it is now works. Well except in IE :?
You'll need to escape those buggers 'inside'. Try a \" , or just a single back-quote ( ` ) in place of the extra ".
Thanks for the help and the greate menu system.
Mark
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

I vaguely remember something about url=#top; instead of just the #
Sorry I can't remember the context.

Ruth
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Re: dynamicly change page link?

Post by kevin3442 »

Hi Mark,
Kevin this sent me to the top of the index page from any page.

Code: Select all

aI("text=Top;url=#;"); 
Odd... I've never had that happen before. Well... let's try another approach.

This syntax in the following code is actually fine:

Code: Select all

aI("text=The Top;url="+this_page+";");
Since the parameter passed to aI() is one long string, it's OK to build the string by concatenating sring literals and string variables, just as you have done. Double quotes are fine here. But...
mark1 wrote:...JavaScript works but then I noticed a problem when the reload button was clicked. When reload is clicked the link has http://myurl.com/pagename.php#MAIN_TOP#MAIN_TOP...
your this_page variable just keeps adding the anchor; #MAIN_TOP in this case. You didn't specify, but I'm guesisng you only get that reload probem if you first use the "The Top" menu item, then reload. This would make sense, because of the following line of js code:

Code: Select all

this_page=document.URL;
Once you jump to the top, the current url is

Code: Select all

http://myurl.com/pagename.php#MAIN_TOP
Then adding #MAIN_TOP again with the following code:

Code: Select all

this_page=this_page+"#MAIN_TOP";
makes the url

Code: Select all

http://myurl.com/pagename.php#MAIN_TOP#MAIN_TOP
If the MAIN_TOP anchor does indeed exist on the page, then a url of #MAIN_TOP should work; no need to put the full path. So, in your javascript that you use to build the menu, instead of

Code: Select all

var this_page=""; 
this_page=document.URL; 
this_page=this_page+"#MAIN_TOP";
You should be able to replace those lines with

Code: Select all

var this_page = "#MAIN_TOP";
Here's another thought. Is MAIN_TOP the name of the anchor you plan to use for all of your pages, or is the "MAIN" part derived from the page name? I'm hoping that the anchor name isn't page specific, but is instead the same on every page. In that case, your aI() item would always be the same, and could be defined without the use of a string variable, like so:

Code: Select all

aI("text=The Top;url=#MAIN_TOP;");
Some food for thought...

Kevin
mark1
Advanced
Advanced
Posts: 12
Joined: Fri Apr 01, 2005 2:32 pm

Post by mark1 »

You were all correct. The problem was I had defined <base href="http://mysite.com" /> This caused the link to go to the home page mysite.com/#MAIN_TOP I removed the base href tag and it all works.

Thanks
mark
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Thanks for posting your solution... could be valuable to others down the road.

Cheers,

Kevin
Post Reply