home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 January / PCWorld_2003-01_cd.bin / Software / Topware / zme / zme5-trcz.exe / ZME5.CZ.chm / openextfile.js < prev    next >
Encoding:
Text File  |  2002-11-29  |  978 b   |  50 lines

  1. function getFilePath() {
  2.   var fromPos, toPos, filePath;
  3.  
  4.   //find the index of the first colon in the string 
  5.   a = location.href.search(":");
  6.  
  7.   //alert(a);
  8.   
  9.   if (a == 2) {
  10.     fromPos = 14;   //prefix = mk:@MSITStore:
  11.   } else if (a == 6) {
  12.     fromPos = 7;   //prefix = ms-its: 
  13.   } else {
  14.     return('');   //no a CHM - return an empty string
  15.   }
  16.  
  17.   //find last back slash
  18.   toPos = location.href.lastIndexOf("\\") + 1;
  19.   if (fromPos > toPos) {
  20.     //fromPos = toPos;
  21.   }
  22.  
  23.   filePath = location.href.substring(fromPos, toPos);
  24.  
  25.   //UnEscape path - EG. Replace %20 with spaces
  26.   filePath = unescape(filePath);
  27.  
  28.   //alert(fromPos + "*" + filePath + "*" + toPos);
  29.  
  30.   return filePath
  31. }
  32.  
  33. function openExtFile(fileName) {
  34.   var filePath, link;
  35.  
  36.   filePath = getFilePath();
  37.  
  38.   if (filePath != "") {
  39.     link = "file:///" + filePath;
  40.   } else {
  41.     link = "";
  42.   }
  43.  
  44.   link += fileName;
  45.  
  46.   location.href = link;
  47.  
  48.   return false;
  49. }
  50.