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:04

Tip: How to make site relative menus work on a CDROM


Poster: CheckeredFlag
Dated: Thursday June 8 2006 - 19:32:12 BST

As you may know, using menus globally throughout your site may require using URLs with site relative paths instead of document relative, such as these:
Code:
subimage="/graphics/arrow.gif";
or
aI("text=Menu Text;url=/dir1/dir2/index.htm;");


However, this technique causes problems when attempting to burn your web onto a CDROM. Since a web browser doesn't know where the document root is located, it will assume the file system root, which will almost certainly be incorrect.

Attempting to use a fully qualified URL instead such as "file:///F:/dir1/dir2..." is a bad idea, since it assumes your users will be running Windows and that their cd drive is always drive F.

Well, I've come up with this hack that works reasonably well:

1) Place your site content into a single directory with a unique name (e.g. DocumentRoot)

2) Place this snippet of JavaScript code into the top of your menu_data.js file:
Code:
siteRootDir="DocumentRoot"; (same as directory name from step 1)
siteRoot="";
if (window.location.protocol == "file:") {
   var h = window.location.href;
   siteRoot = h.substr(0, h.indexOf(siteRootDir+"/") + siteRootDir.length);
}


3) Then change all your menu site-relative url references to look similar to this:
Code:
subimage=siteRoot+"/graphics/arrow.gif";
aI("text=Menu Text;url="+siteRoot+"/dir1/dir2/index.htm;");


This technique seems to work well on the browsers and platforms I've tested. In addition, the menu_data.js will continue to work on a live webserver as well, so there is no need to have two different versions for web and for cd.

Hope this helps someone with similar needs!

Marco Moreno

P.S. Suggestion: Perhaps Milonic could predefine a specific variable name (e.g. cdSiteRoot) and perform this magic behind the scenes so that urls don't have to be modified.