Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:46

dynamicly change page link?


Poster: mark1
Dated: Wednesday April 27 2005 - 22:30:15 BST

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:
<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://www.milonic.com/;target=_blank;");
}
    drawMenus();
</script>


Thanks for the help and the great menu system.


Poster: kevin3442
Dated: Thursday April 28 2005 - 19:11:07 BST

Hi Mark,

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

Code:
aI("text=Top;url=#;");


I believe that should take you to the top of any page.

Cheers,

Kevin


Poster: John
Dated: Thursday April 28 2005 - 21:18:26 BST

You can't have more than one set of "" in your aI statements...
Code:
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 ".


Poster: mark1
Dated: Thursday April 28 2005 - 22:41:31 BST

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:
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 :?
Quote:
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


Poster: Ruth
Dated: Friday April 29 2005 - 22:15:34 BST

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

Ruth

Re: dynamicly change page link?


Poster: kevin3442
Dated: Saturday April 30 2005 - 0:15:13 BST

Hi Mark,

Quote:
Kevin this sent me to the top of the index page from any page.
Code:
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:
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:
this_page=document.URL;

Once you jump to the top, the current url is
Code:
http://myurl.com/pagename.php#MAIN_TOP

Then adding #MAIN_TOP again with the following code:
Code:
this_page=this_page+"#MAIN_TOP";

makes the url
Code:
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:
var this_page="";
this_page=document.URL;
this_page=this_page+"#MAIN_TOP";

You should be able to replace those lines with
Code:
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:
aI("text=The Top;url=#MAIN_TOP;");


Some food for thought...

Kevin


Poster: mark1
Dated: Friday June 10 2005 - 12:07:53 BST

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


Poster: kevin3442
Dated: Friday June 10 2005 - 23:33:48 BST

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

Cheers,

Kevin