Get relative link to project root

The following function returns the relative path to the project start page. Usefull if you want to create dynamic links.

This script works with WebHelp and CHM.

function RootPath() {

try{
  var path = _getRelativePath(document.location, gsStartPage);
} catch(e) {//Normally this happens because we're in a CHM
  var CHM = function () {

   var location = document.location.toString();
   var gsStartPage = location.split(/::\//g);

   var relpath = gsStartPage[1].split(/\//g);
   var path = '';

   for(var i=0;i<relpath.length-1;i++) {
    path = '../'+path;
   }
   return path;
  }
  try{if(gbIE){}}catch(e){path = CHM();}
}

return path;
}

Tags: